The most common ways to list packages in Python is pip list
and pip freeze
. To see more, check List all installed packages in Python. So, what does each of them and is one of them better than the other?
Prerequisites
- Python
- pip
Solution
pip list
Simply put, pip list
list all installed packages including the so-called editables. Editable packages such as setuptools
are Python packages that helps you run local projects in a “development mode” or “editable” mode if you will.
pip freeze
On the other hand, pip freeze
outputs only packages installed using pip
to a text file usually known as requirements.txt
. So, that’s why you might see lower number of packages when running this command.
But, if you want to list all of them including setuptools
and pip
, run:
pip freeze -all
Now, why do we need pip freeze
? Well, for a few reasons. For instance:
- If you want to preserve your package versions and apply them to another project, right?!
- To address any issue related to dependency conflicts. Most likely to happen when installing global packages available to all projects on your machine, instead of local (user) packages.
The common command being:
pip freeze -all > requirements.txt
will save all installed packages to requirements.txt
. Consecutively, to apply them to another project, you need to run the following command:
pip install -r requirements.txt
Conclusion
pip freeze
(without the-all
option) shows packages you installed viapip
. Doesn’t include all packages such assetuptools
andpip
.- The main difference between
pip list
andpip freeze -all
being that the latter one output the package list to arequirements.txt
file, so if you need the same package versions in another project you can just copy that file.
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.