Check the Versions of Python Packages

Modified: | Tags: Python

This article explains how to check the versions of packages and modules used in Python scripts, as well as the versions of packages installed in your environment.

To check the version of Python itself, refer to the following article.

Check package versions in a Python script: __version__

To check the version of a package used in a Python script, use the __version__ attribute.

import pandas as pd

print(pd.__version__)
# 2.0.1

The __version__ attribute is recommended by Python Enhancement Proposals (PEP) and is commonly implemented across many packages.

It is important to note that not all packages include the __version__ attribute, as it is not mandatory.

In addition to the __version__ attribute, certain packages, including NumPy and pandas, offer functions and additional attributes for accessing more detailed version information.

Note that standard library modules such as math and os do not have a __version__ attribute. These modules do not have individual version numbers and instead follow the version of the Python interpreter.

Check installed package versions: pip

For Python environments managed with pip, you can check information about the installed packages using the following commands. Run these commands in a command prompt or terminal.

In certain environments, you may need to use pip3 instead of pip. For basic information on how to use pip, such as installing, updating, and uninstalling packages, see the following article.

List installed packages: pip list

pip list displays a list of installed package names and their version numbers.

$ pip list
Package            Version
------------------ ---------
absl-py            0.1.10
agate              1.6.0
agate-dbf          0.2.0
agate-excel        0.2.1
agate-sql          0.5.2
appnope            0.1.0
...

pip list supports the following options:

  • --format <format-name>
    • Sets the display format (columns, freeze, json)
  • -o, --outdated
    • Displays only out-of-date packages
  • -u, --uptodate
    • Displays only up-to-date packages

Refer to the following article for more information.

List installed packages: pip freeze

pip freeze displays a list of installed package names and their version numbers in the freeze format.

$ pip freeze
absl-py==0.1.10
agate==1.6.0
agate-dbf==0.2.0
agate-excel==0.2.1
agate-sql==0.5.2
appnope==0.1.0
...

Unlike pip list --format freeze, pip freeze does not include package management tools such as pip, setuptools, distribute, and wheel by default, as they are generally not required when recreating an environment. If needed, these tools can be included using the --all option.

You can save the output of pip freeze to a text file to enable bulk installation of packages at specific versions. Refer to the following article for more information.

View detailed information about a package: pip show

pip show <package-name> displays detailed information about a package, such as its version, license, dependencies, and more.

$ pip show pandas
Name: pandas
Version: 2.0.1
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: 
Author: 
Author-email: The Pandas Development Team <pandas-dev@python.org>
License: BSD 3-Clause License
...
Location: /opt/homebrew/lib/python3.11/site-packages
Requires: numpy, numpy, python-dateutil, pytz, tzdata
Required-by: 

Check installed package versions with conda: conda list

For Python environments managed with Anaconda, use conda list to view installed packages in the current virtual environment.

If the environment is not activated, you can specify the environment using conda list -n <environment-name>.

Related Categories

Related Articles