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?
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.
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
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
pip freeze(without the
-alloption) shows packages you installed via
pip. Doesn’t include all packages such as
- The main difference between
pip freeze -allbeing that the latter one output the package list to a
requirements.txtfile, 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.