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

13 Answers

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

0

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

select the appropriate version

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

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!

1

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

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

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

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

Dropdown

1

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

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.

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

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 

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.

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'.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy