First of all, I’m using Visual Studio Code as my IDE. The full error message is this:
File "c:UsersAlexDocumentsCodingPythonezpz.py", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
However, when I do "pip install numpy", it says, "Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: numpy in c: blah blah"
Also, when I use python in the terminal and type "import numpy" no error occurs and I can use the module normally. Is there a problem with VS Code?
As a mentioned above, I’ve tried "import numpy" in the terminal and it worked.
3
Answers
First of all, please include the full error. But anyways here is your problem as far as I can tell: You have multiple conflicting versions of Python. I would recommend you to delete the python installation after "numpy in c: " Then uninstall and reinstall python. Just incase run the command in command prompt as ADMINISTRATOR. If that doesn’t work, I really dont know how to help you.
At a guess, I’d say that you probably have multiple python interpreters installed. One is being used by default in the terminal, and VSCode is configured to use another.
In the lower right of your VSCode window, you should see a python version. Click on that and it will show you the path to the current python interpreter, as well as any other available options.
Then, you can check which version is being used in the terminal. If it’s a bash terminal, type
which python
orwhich python3
(try both, it depends on your OS and configuration). If it’s Powershell, typeGet-Command python | fl *
. These commands will show you which python interpreter is being used at the terminal.If you see that VSCode is indeed using a different interpreter, you have a few options for how to proceed.
numpy
). Here’s a good tutorial if you’re just getting started.Hopefully this goes without saying, but you need to make sure you don’t have programs that depend on the python version that’s getting demoted!
If you’re on Linux, you need to be much more careful. Some distros (Ubuntu, for example) come with a pre-installed python version that must remain installed and must remain the default. You can break your system messing with this.
If you’re on Mac, then I don’t have a lot of personal experience to help you so I’d say proceed with caution or choose one of the other options.
If you run your program with python3 like python3 program.py, you need to use pip3 instead of pip to install libraries, so maybe you should try :
Also, maybe VScode is not running the good version of python, so you can try to change it