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:\Users\User\AppData\Local\Programs\Python\Python39\python39.zip', 'C:\Users\User\AppData\Local\Programs\Python\Python39\DLLs', 'C:\Users\User\AppData\Local\Programs\Python\Python39\lib', 'C:\Users\User\AppData\Local\Programs\Python\Python39', 'C:\Users\User\Documents\mednotes\.venv', 'C:\Users\User\Documents\mednotes\.venv\lib\site-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
CodePudding user response:
Are you sure pip
installed them to the correct place? Can you see the packages you installed under the C:\Users\User\Documents\mednotes\.venv\lib\python3.9\site-packages
folder?
I would double-check where python3
and pip
are getting picked up from. Try where python3
and where pip
.
CodePudding user response:
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.