billboard billboard - 9 months ago 122
Python Question

No module named 'numpy': Visual Studio Code

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.

Answer Source

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

Try this:

import sys


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?