pip list vs pip freeze, and other ways to check installed packages in Python environment


n this blog post, we’ll explore different ways to check the installed packages in a Python environment using various commands and tools.

Using pip list

The pip list command is the most commonly used command to check the installed packages in a Python environment. It displays all the packages installed in the environment along with their version numbers in a tabular format.

To use pip list, open a command prompt or terminal and type:

pip list

This will display a list of all the installed packages in the environment.

The output of pip list includes additional information such as whether the package is installed globally or locally, and whether it is a dependency of any other package.

Using pip freeze

The pip freeze command is another useful command to check the installed packages in a Python environment. It lists all the installed packages along with their version numbers, but it displays them in a different format compared to pip list.

The output of pip freeze is useful for replicating the environment because it lists the packages in a format that can be directly used in a requirements file.

To use pip freeze, open a command prompt or terminal and type:

pip freeze

This will display a list of all the installed packages in the environment in the format used for requirements files.

However, it’s important to note that pip freeze only lists packages that were installed using pip. It does not include packages that were installed using other package managers like conda, easy_install, or manually installed packages.

To install packages from a requirements.txt file using pip, you can use the following command:

pip install -r requirements.txt

This command installs all the packages listed in the requirements.txt file. The -r option specifies that the packages should be installed from a requirements file.

The requirements.txt file should list all the required packages along with their version numbers, separated by new lines. Here’s an example requirements.txt file:

numpy==1.19.3
pandas==1.1.5
matplotlib==3.3.3

This file lists the numpy, pandas, and matplotlib packages with their respective version numbers.

To install the packages listed in the requirements.txt file, save the file to your working directory and run the following command:

pip install -r requirements.txt

This will install all the packages listed in the requirements.txt file.

Using conda list

If you’re working with Python using the conda package manager, you can use the conda list command to check the installed packages.

To use conda list, open a command prompt or terminal and type:

conda list

This will display a list of all the installed packages in the conda environment.

Using easy_install –list

If you’ve installed packages using easy_install, you can use the easy_install –list command to check the installed packages.

To use easy_install –list, open a command prompt or terminal and type:

easy_install --list

This will display a list of all the installed packages using easy_install.

Manually installed packages

If you’ve installed packages manually, i.e., not using any package manager, you can use the package manager specific to your operating system to check the installed packages.

For example, on a Linux system, you can use the dpkg command to list all the manually installed packages:

dpkg --get-selections | grep -v deinstall

On a macOS system, you can use the brew command to list all the manually installed packages:

brew list

Author: robot learner
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source robot learner !
  TOC