Module not found error in VS code despite the fact that I installed it
Solution 1
sudo pip install
is most likely installing globally into a Python interpreter that is different than the one that you have selected in VS Code. Please select the Python interpreter you want to use and then install explicitly using that interpreter (if you're not using a virtual environment then use something like /path/to/python -m pip install SimpleITK
, although I strongly recommend using a virtual environment and to not install packages globally).
Solution 2
After install new module with pip
if vscode not recognize it, reloading vscode may work.
- Ensure that the module installed inside virtual environment
Create and activate virtualenv
python3 -m venv env
source env/bin/activate
Use correct way of install module with pip
python3 -m pip install {new_module}
- Reload vscode: Ctrl+Shift+P, select Reload window
Now vscode will know new module and autocomplition works.
Solution 3
In Mac, correctly selecting the Python Interpreter worked for me:
From within VS Code, select a Python 3 interpreter by opening the Command Palette (⇧⌘P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too):
No interpreter selected
The command presents a list of available interpreters that VS Code can find automatically, including virtual environments. If you don't see the desired interpreter, see Configuring Python environments.
Source :VS Code Select Interpreter
Solution 4
I ran into this problem with VSCode and resolved it by setting my Python interpreter within VSCode to the same as the one in my system path (type "echo %PATH%" on Windows and look for Python) via the process here: https://code.visualstudio.com/docs/python/python-tutorial#_select-a-python-interpreter
Solution 5
This error: your vscode use other python version. This solution change vscode use current python.
-
In terminal find current python version:
py --version
-
In vscode Press
Ctrl+Shift+P
then type:Python: Select Interpreter
-
Select current python version
An Ignorant Wanderer
Updated on December 22, 2021Comments
-
An Ignorant Wanderer over 2 years
I'm trying to debug some python code using VS code. I'm getting the following error about a module that I am sure is installed.
Exception has occurred: ModuleNotFoundError No module named 'SimpleITK' File "C:\Users\Mido\Desktop\ProstateX-project\src\01-preprocessing\03_resample_nifti.py", line 8, in <module> import SimpleITK as sitk
I installed the module using
sudo pip install SimpleITK
I know that it was installed because I was getting a similar error when I ran the code through the command line, and it was fixed by doing the above. I don't understand why VS code does not recognize that
-
Borhan Kazimipour almost 5 yearsMaybe Python path has not been updated in the VS code. Have you checked that? Perhaps closing all instances of VS code and then trying again might resolve the problem.
-
-
An Ignorant Wanderer almost 5 yearsSo now I'm having the problem with the pandas module. I ran pip list, pandas is installed. The python version in VS Code is 2.7, and it does support pandas, so I'm not sure what's going on
-
Robin Betts over 4 yearsThis answer solved my problem. Even though I set up a virtual environment, the integrated terminal was natively pointing at a different Python. So modules installed by running
pip
in the terminal's Python were available to the terminal, but not accessible to workspace files running in it. Any idea how to get the terminal to use the same Python as the rest of the workspace? i.e. The one in the virtual environment? -
Brett Cannon over 4 yearsIf you have a virtual environment selected in the extension (and the extension is loaded), then when you open a new terminal the extension will activate that shell for the virtual environment so that
python
will point to the interpreter you want. -
Michael Ramos about 4 yearsvscode let's you select the virtualenv if it is activated
-
wildernessfamily over 2 yearsI had the same problem. I bet you have a shebang statement at the top of your file. If you do. 1. Visual Studios settings 2. Under "Code-runner->Code-runner: Respect Shebang" section or just do a search for "Code-runner: Respect Shebang" 3. Uncheck weather to respect Shebang to run code. Now it will run under the virtual environment and find the modules that you installed using pip! :)
-
JeroenDV over 2 yearsStep 2 is done on macOS by pressing Cmd + Shift + P, select Reload Window