Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip installed packages not found in virtual environment

I am working with venv in VS code on windows 10, and it kept throwing ModuleNotFoundError, even if I have already tried py -m pip install <package name>. The weirdest part was that pip freeze or pip list returns nothing.

If I navigate to the env/Lib/site-packages folder, I can see that the package folder is already there, so I am assuming the package has been installed.

I think it's worth noting that the above problem only happens after I activated the virtual environment, and pip freeze is still working normally when I am not in venv.

Some details: (can provide more if needed)

  • windows 10
  • VS code 1.59.0
  • python 3.9.6 64-bit

Any help provided would be greatly appreciated!

like image 742
Pin-Hao Avatar asked Nov 18 '25 12:11

Pin-Hao


1 Answers

The query is still unclear. Can you show the exact error msg thrown? i.e. message after ModuleNotFoundError.

pip is a package installer and it is present by default when you create a new virtual environment

if the error still persists, you can try this:

First reason to why pip freeze or pip list doesn't show anything is that you don't have any packages installed in your virtual environment. If it doesn't throw any other error messages, it means it working just fine and showing a null list. The packages may be installed outside the virtual env.

Second reason is that somehow your package installer pip is uninstalled from the virtual env. But in this case whenever you use any pip command it always throws an error something like 'pip' module not found.

To resolve this (second reason)

  • you can simply deactivate the virtual env and create a new one. python -m venv new_env_name. Then install all your libraries at once using the requirements.txt file.
  • Or you will have to download and install pip manually in your virtual env. Since I find it cumbersome, I prefer the previous workaround.
like image 86
Pushkar Avatar answered Nov 21 '25 01:11

Pushkar