note.nkmk.me

Check all installed Python packages with pip list / pip freeze

Posted: 2021-01-06 / Tags: Python, pip

In pip, the package management-system for Python, you can check the list of installed packages with pip list and pip freeze commands.

With pip list, it is possible to select and output the latest version (= uptodate) packages, non-latest version (= outdated) packages, packages that are not dependencies of other packages, etc.

pip freeze is useful for creating requirements.txt, which is a configuration file for installing packages in bulk.

This article describes the following contents.

  • Difference between pip list and pip freeze
  • Select the output format: --format
  • List uptodate packages: -u, --uptodate
  • List outdated packages: -o, --outdated
  • List packages that are not dependencies of other packages: --not-required

This article does not describe all the options, see the official documentation for more details.

For basic information on how to use pip, such as installing, updating, and uninstalling packages, please see the following article.

The following examples are running on pip 18.1.

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

Sponsored Link

Difference between pip list and pip freeze

The output results of pip list and pip freeze in the same environment are as follows.

$ 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 difference between pip list and pip freeze is:

  • The output format
  • Whether the result includes packages for package management (ex. pip, wheel, setuptools)

The output format of pip list may differ depending on the version of pip and settings, but the output format of pip freeze is <package-name> == <version>.

The format of pip freeze is the format for requirements.txt, which is a configuration file for installing packages in bulk. If you output pip freeze as a file with redirection > and use it in another environment, you can install the same packages at once.

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

pip freeze does not output pip itself or packages for package management such as setuptools andwheel. These packages are not needed for porting the environment using requirements.txt mentioned above.

Note that if you add the --all option to pip freeze, packages such as pip will also be output.

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

As explained below, pip list can be used to select and output the latest version (= uptodate) packages, non-latest version (= outdated) packages, packages that are not dependencies of other packages, etc.

Therefore, you should use pip list and pip freeze as follows:

  • If you want to check a list of packages with various conditions, use pip list.
  • If you want to create requirements.txt, use pip freeze.

Select the output format: --format

In pip list, you can select the output format with the --format option.

$ pip list --format <format>

<format> can be columns, freeze, or json. In pip 18.1, columns is the default. In previous versions, the format legacy could be specified, but not in 18.1.

$ 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 uptodate packages: -u, --uptodate

pip list with -u or --uptodate outputs only the packages that have been updated to the latest version.

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

List outdated packages: -o, --outdated

pip list with -o or --outdated outputs only updatable packages that are not the latest version.

If the output format is columns or json, the currently installed version and the latest version are output together.

$ 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"}

If the output format is freeze, only the currently installed version is output.

$ pip list -o --format freeze
setuptools==39.2.0
wheel==0.31.1

List packages that are not dependencies of other packages: --not-required

pip list with --not-required outputs only packages that are not dependent on 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 output by pip list --not-required will not break dependencies of other packages even if they are uninstalled. This is useful for finding packages that can be uninstalled in an environment where many packages are installed.

Note that only dependencies are checked, and those used as external commands, such as pip, are also listed.

Sponsored Link
Share

Related Categories

Related Articles