How to List Installed Python Packages with pip list/freeze

Modified: | Tags: Python, pip

With pip, the Python package installer, you can list installed packages using the pip list and pip freeze commands.

pip list can filter and show packages based on conditions such as being up-to-date, outdated, or not required by other packages.

pip freeze is useful for creating a requirements.txt file, which can be used to install packages in bulk.

This article does not cover all options. See the official documentation for more details.

For basic pip usage, such as installing, updating, and uninstalling packages, see the following article.

If you are using Anaconda, you can list installed packages with conda list.

Differences between pip list and pip freeze

Below are examples of the output from pip list and pip freeze in the same environment.

$ pip list
Package    Version
---------- -------
future     0.16.0
pip        18.1
setuptools 39.2.0
six        1.11.0
wheel      0.31.1
$ pip freeze
future==0.16.0
six==1.11.0

The differences between pip list and pip freeze lie in their output formats and whether they include package management tools like pip.

While the output format of pip list may vary with the version of pip and its settings, pip freeze consistently uses the <package-name>==<version> format, suitable for requirements.txt.

Redirecting the output of pip freeze to a file using > enables you to install the same packages in another environment.

$ pip freeze > requirements.txt
$ pip install -r requirements.txt

pip freeze excludes package management tools such as pip, wheel, and setuptools, which are not needed for porting environments via requirements.txt.

Adding the --all option to pip freeze outputs packages like pip.

$ pip freeze --all
future==0.16.0
pip==18.1
setuptools==39.2.0
six==1.11.0
wheel==0.31.1

As shown below, pip list can filter packages based on various conditions.

Therefore, use pip list and pip freeze in the following ways:

  • Use pip list to list packages under specific conditions
  • Use pip freeze to create requirements.txt

Select the output format: --format

With pip list, you can select the output format using the --format option.

$ pip list --format <format>

<format> can be columns (default as of pip 25.0.1), freeze, or json. The legacy format, which was available in earlier versions, is no longer supported in recent releases of pip.

$ pip list --format columns
Package    Version
---------- -------
future     0.16.0
pip        18.1
setuptools 39.2.0
six        1.11.0
wheel      0.31.1
$ pip list --format freeze
future==0.16.0
pip==18.1
setuptools==39.2.0
six==1.11.0
wheel==0.31.1
$ pip list --format json
{"version": "0.16.0", "name": "future"}, {"version": "18.1", "name": "pip"}, {"version": "39.2.0", "name": "setuptools"}, {"version": "1.11.0", "name": "six"}, {"version": "0.31.1", "name": "wheel"}

List up-to-date packages: -u, --uptodate

pip list with the -u or --uptodate option lists only up-to-date packages.

$ pip list -u
Package Version
------- -------
future  0.16.0
pip     18.1
six     1.11.0

List outdated packages: -o, --outdated

pip list with the -o or --outdated option lists only outdated packages.

When the output format is set to columns or json, both the currently installed version and the latest version are displayed.

$ pip list -o
Package    Version Latest Type
---------- ------- ------ -----
setuptools 39.2.0  40.4.3 wheel
wheel      0.31.1  0.32.1 wheel
$ pip list -o --format json
{"latest_filetype": "wheel", "version": "39.2.0", "name": "setuptools", "latest_version": "40.4.3"}, {"latest_filetype": "wheel", "version": "0.31.1", "name": "wheel", "latest_version": "0.32.1"}

Using freeze with -o or --outdated will result in an error.

% pip list -o --format freeze
ERROR: List format 'freeze' can not be used with the --outdated option.

List packages not required by others: --not-required

pip list with the --not-required option lists only packages that are not dependencies of other installed packages.

$ pip list --not-required
Package    Version
---------- -------
future     0.16.0
pip        18.1
setuptools 39.2.0
six        1.11.0
wheel      0.31.1

Packages shown with this option are standalone and can be uninstalled without affecting the dependencies of other packages. This feature is particularly helpful for cleaning up an environment cluttered with many installed packages.

It is important to note that this option checks only for package dependencies. Therefore, packages that are used as external commands, including pip itself, will appear in the list.

Related Categories

Related Articles