Why would "pip freeze" print out packages that I did not install?

I have two Ubuntu 18 machines. In one machine, I have a fresh installation of Ubuntu, and I created a virtual environment using python3 -m venv env. When I activate this environment using source env/bin/activate and then run pip freeze, it doesn't print anything out. This is what I would have expected, since I hadn't installed any Python packages for this virtual environment yet.

However, in the second machine, I have an older installation of Ubuntu, which is a bit messy and has lots of packages installed already. I also created a virtual environment and activated it, but when I run pip freeze here, it prints out a very large number of Python packages. This was surprising to me, because I thought that pip freeze prints out the Python packages that have already been installed in that environment; and in this case, I hadn't installed any Python packages. Furthermore, I then looked into the site-packages folder of the virtual environment, and it didn't contain any of these Python packages.

So my question is: What are some possible reasons why pip freeze is printing out all these packages, when I did not actually install them in the environment?

1 Answer

You need to use the -l or --local option to freeze only the local packages in the virtual environment (and not the global ones)

pip freeze -l > requirements.txt 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like