python,

Python: pip list vs pip freeze (-all)

Nov 18, 2022 · 2 mins read · Post a comment

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:

  1. If you want to preserve your package versions and apply them to another project, right?!
  2. 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 via pip. Doesn’t include all packages such as setuptools and pip.
  • The main difference between pip list and pip freeze -all being that the latter one output the package list to a requirements.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.