With pip, the Python package installer, you can list installed packages using the pip list
and pip freeze
commands.
pip list
can filter and display packages by conditions like latest, outdated versions, and those not required by others.
pip freeze
is useful for creating requirements.txt
, which is used for bulk installation of packages.
- How to install Python packages with pip and requirements.txt
Contents
- Differences between pip list and pip freeze
- Select the output format: --format
- List up-to-date packages: -u, --uptodate
- List outdated packages: -o, --outdated
- List packages not required by others: --not-required
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.
- How to use pip (Install, update, uninstall packages)
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 listPackage Version---------- -------future 0.16.0pip 18.1setuptools 39.2.0six 1.11.0wheel 0.31.1
$ pip freezefuture==0.16.0six==1.11.0
The differences between pip list
and pip freeze
are the output format and whether package management tools like pip
are included or excluded.
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 pip freeze
output to a file using >
enables bulk installation of identical packages in a different environment.
- How to install Python packages with pip and requirements.txt
$ 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
, making it ideal for this purpose.
Adding the --all
option to pip freeze
outputs packages like pip
.
$ pip freeze --allfuture==0.16.0pip==18.1setuptools==39.2.0six==1.11.0wheel==0.31.1
As explained below, pip list
can filter packages based on various conditions.
Therefore, you should use pip list
and pip freeze
as follows:
- Use
pip list
to list packages under specific conditions - Use
pip freeze
to createrequirements.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
, freeze
, or json
. As of pip version 23.1, columns
is the default format. The legacy
format, available in earlier versions, is no longer supported in recent versions of pip.
$ pip list --format columnsPackage Version---------- -------future 0.16.0pip 18.1setuptools 39.2.0six 1.11.0wheel 0.31.1
$ pip list --format freezefuture==0.16.0pip==18.1setuptools==39.2.0six==1.11.0wheel==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 outputs only up-to-date packages.
$ pip list -uPackage Version------- -------future 0.16.0pip 18.1six 1.11.0
List outdated packages: -o
, --outdated
pip list
with the -o
or --outdated
option outputs only upgradable packages that are not the latest version.
When the output format is set to columns
or json
, both the currently installed version and the latest version are displayed.
$ pip list -oPackage Version Latest Type---------- ------- ------ -----setuptools 39.2.0 40.4.3 wheelwheel 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 freezeERROR: List format 'freeze' can not be used with the --outdated option.
List packages not required by others: --not-required
Using pip list
with the --not-required
option lists only packages that are not dependencies of other installed packages.
$ pip list --not-requiredPackage Version---------- -------future 0.16.0pip 18.1setuptools 39.2.0six 1.11.0wheel 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.