I am running VSCode on Windows 10. I’ve set up a virtual environment and have installed a number of packages to the local site library.
I’ve activated my environment (The terminal prompt shows a .venv string)
However, when I attempt to import any of my local modules, I get an ‘Module not found’
error.
Doing a pip list shows that the modules do exist in the virtual env.
I’ve verified that I’m running the Python executable in the virtual environment.
Printing sys.path gives the following output:
[”, ‘C:UsersUserAppDataLocalProgramsPythonPython39python39.zip’, ‘C:UsersUserAppDataLocalProgramsPythonPython39DLLs’, ‘C:UsersUserAppDataLocalProgramsPythonPython39lib’, ‘C:UsersUserAppDataLocalProgramsPythonPython39’, ‘C:UsersUserDocumentsmednotes.venv’, ‘C:UsersUserDocumentsmednotes.venvlibsite-packages’]
The AppData path is, I believe the global Python namespace. Why is this even in my
sys.path in my local virtual env? I added the last two paths manually to see if this
would fix anything but no luck.
I’m really stuck here. Anybody have any suggestions for fixing this?
Thanks
2
Answers
Are you sure
pip
installed them to the correct place? Can you see the packages you installed under theC:UsersUserDocumentsmednotes.venvlibpython3.9site-packages
folder?I would double-check where
python3
andpip
are getting picked up from. Trywhere python3
andwhere pip
.A virtual environment is a built-in way to create an environment to isolate the packages you install per workspace.
When you use a virtual environment, it will isolate the local package.
You can use shortcuts "Ctrl+Shift+P" and type "Python: Select Interpreter" to choose the correct interpreter.
Another way is to use
conda install packageName
command to install the package in the virtual environment.