42

I'm trying to setup Visual Studio Code for python development

to begin with, I've installed

  1. Anaconda Python
  2. Visual Studio Code

and in a new file I have the following code

import numpy as np
import pandas as pd
from pandas import Series, DataFrame

upon hitting Ctrl+Shift+B I get the following error

import numpy as np

ImportError: No module named 'numpy'

Also, is there python interactive window in VS Code? How to open it.

4
  • 3
    Do you have mutiple Python installations on your system? Commented Oct 21, 2016 at 21:14
  • I don't see where you said you installed numpy. (Does it come with Anaconda or Visual Studio Code? I'm not familiar with those.) Commented Oct 21, 2016 at 21:24
  • Numpy comes with Anaconda, I have Anaconda 2.7 and 3.5 64-bit versions Commented Oct 21, 2016 at 21:53
  • see solution stackoverflow.com/questions/29987840/… for using anaconda python environment and python libraries. Commented Sep 2, 2021 at 21:00

16 Answers 16

61

Changing python environment in VS code helped me. Default the visual studio code takes original Python environment, it requires numpy to install. If you have anaconda python (numpy comes with it) installed, you could switch the original python environment to anaconda python environment in visuals studio code. This can be done from the command palette Ctrl+Shift+P in visual studio

Check this link for how to switch from original python to anaconda python environment, specifically:

Snippet from VSCode instructions enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I'm getting the same error even after creating a separate environment via anaconda and then choosing that environment in VS Code
@newtothis See the solution at the following link, which helped me. stackoverflow.com/a/71039682/3006011
16

You may not have numpy installed on the version of python you are running.

Try this:

import sys

print(sys.version)

Is the printed version Anaconda? If you installed Anaconda python, it should come with numpy already installed. If it turns out to be another version of python you are accessing inside Visual Studio Code that doesn't have numpy installed, then that's what you need to fix.

The version of python that is called depends on which version of python comes up in your PATH variable first. Type into a terminal: echo $PATH. The output should look like this with Anaconda bin first: /Users/jlzhang/anaconda/bin:/usr/local/bin:/usr/bin:/bin

If you do not have Anaconda bin first, you can add this to your ~/.bashrc file: echo

# Use Anaconda python

export PATH="/Users/jlzhang/anaconda/bin:$PATH"

Restart a terminal and Visual Studio Code and see if you are now running Anaconda python.

Hope it helps/ Did it work?

1 Comment

The issue was with the path, I apparently have installed regular official python and Anaconda python, the official python showedup first in the path list. I uninstalled it and it appears to have removed from PATH. If i need to have official version also, may be i could have just switched the order, but i did not try that
7

You have to make sure VSCode selects the python interpreter bundled with Anaconda. If using Anaconda, please do not pip install your science packages.

The solution is as follows for me with Anaconda:

  1. To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).

enter image description here

  1. Select python bundled by Anaconda Select the correct interpreter..

Numpy, scipy, and the like should now no longer have a warning!

Comments

4

select the appropriate version

click on python and select the appropriate version. your issue will be solved

Comments

4

If you are using jupiter notebook in VS Code, you need to select proper evvironmemt for it: enter image description here

1 Comment

This was critical in VS Code (on Mac M1) to allow myself to run pip and install packages (without anaconda).
2

We've found that simply changing the environment worked. Right-click on "Python Environments" and choose "Add/Remove Python Environments" and choose 3.5 instead of 3.6:

Add/Remove Python Environments

Comments

2

if you are at VSC jupyter, you should check this:

Like this (You can see this at the top right)

Comments

1

Choose Python in the dropdown(default is PowerShell) and execute pip install NumPy pandas etc.

Dropdown

1 Comment

This question already has an accepted answer, as well as another answer that seems to cover your approach as well.
1

1.Numpy have showing error when importing at VS CODE

When i Run the code it show No module named 'numpy' .Although i check by pip install numpy it show satisfy that its already intsall

Then i found solution 1.Press Ctrl+shift+P 2.type python interpreter and click on it. 3.Then choose The Global interpreter shown in image attached. 4.again run the code no error. No Error,Done 100%

Comments

1

Even after conda(Anaconda) is installed and the anaconda version of python is selected(using ctrl+shift+p and selecting Python: Select interpreter) on the VS code python extension interpreter the version of the kernel used to run the notebook can be different. Below is when the default installation of python is selected on the top right corner of VS code: Numpy module not found with default python kernel But when the anaconda version of python is selected on the top right corner of VS code, the numpy module is imported and runs(look for the currently selected one on the top menu). enter image description here

Note after installing the python extension on VS code and selecting the python interpreter, it will automatically load and show you which interpreters you have on your system to choose from.

Comments

0

On my laptop, i found that there are some version of python installed (checkout picture that i inserted below)

Picture for some version of python installed

One of them is python 3.7.6 which installed together when i installed Anaconda (I installed it the day before). I assumed that it was the updated version of python. So i changed my Jupyter kernel to that version of Python. It works for me.

Comments

0

you can do something else in cmd type :

cmd) where pip

and cmd return some address after you should install NumPy for all addresses and make sure installed NumPy in all them ->

cmd) ADDR1 install numpy

cmd) ADDR2 install numpy

... and all addresses

Comments

0

I used to get the same error.

if you installed python and pip then run this code on the vs code terminal 'pip install numpy'.

1 Comment

You shouldn't be using numpy if you already installed conda
0

If you have tried pip install numpy and it is not working,copy paste this to your cmd

pip install numpy  --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org

Comments

0

I'm my case I was receiving a message in the integrated terminal of Visual Studio Code:

ModuleNotFoundError: No module named 'scipy'

But the terminal was showing that scipy was installed:

Requirement already satisfied: scipy in ./opt/anaconda3/lib/python3.9/site-packages (1.7.1)

I discover that is because the vscode integrated terminal was using the default python version installed before Anaconda. The steps provided in others answers, like change the interpreter, did not solved my problem. So, I just deactivated Anaconda:

conda deactivate

I Installed the desired module in the default python installation:

pip install scipy

And then I reactivated conda:

conda activate

After it, everything works now.

Comments

0

I did have the same problem with VS Code kept asking me to choose the Python interpreter.

Here's my solutions:

  1. Download the latest python from python.org

  2. Check how many versions of python are installed in your system. If you have more than one, uninstall the one you don't need.

  3. If you have Anaconda, it's best to uninstall it too.

  4. The key to this problem is the hidden folder where Python is installed. It is inside C:\Users[your folder name]\Appdata

The solution is to make this Appdata folder not hidden. So, you need to right click AppData and change the attribute to make it not hidden. Make sure you choose to apply the option globally, not just for the current user.

  1. Restart VS Code.

  2. Select your interpreter that points to the version of Python you want to use.

  3. If all else fails, use different Python IDE interpreter. PyCharm Community Version is free to use and download.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.