- Check the version of Python package/library
- Get package version in Python script: __version__ attribute
- Check package version with pip command: pip list , pip freeze , pip show
- List installed packages: pip list
- List installed packages: pip freeze
- Check details of installed packages: pip show
- Check package version with conda command: conda list
Check the version of Python package/library
This article explains how to check the versions of packages (libraries) and modules used in Python scripts, and the versions of packages installed in your environment.
If you want to check the version of Python itself, see the following article.
Get package version in Python script: __version__ attribute
To get 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, recommended by Python Enhancement Proposals (PEP), is available in many packages.
Note that not all packages have the __version__ attribute because it is not mandatory.
In addition to the __version__ attribute, some packages, such as NumPy and pandas, provide functions and attributes that display more detailed information.
Note that the __version__ is not set for the standard library modules such as math and os . Modules in the standard library do not have individual versions but follow the Python version.
Check package version with pip command: pip list , pip freeze , pip show
If you are using the Python package management system, pip , you can check the information about the installed packages using the following commands. Run these commands in the command prompt or terminal.
In some environments, use pip3 instead of pip . In some cases, pip is for Python2, and pip3 is for Python3.
For basic information on how to use pip, such as installing, updating, and uninstalling packages, please see the following article.
List installed packages: pip list
pip list displays a list of installed package names and 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 .
The pip list command also accepts the following options:
- —format
- Set the display format ( columns , freeze , json )
- Show only out-of-date packages
- Show only the latest packages
Refer to the following article for more information.
List installed packages: pip freeze
pip freeze displays a list of installed package names and version numbers in 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 .
The difference between pip freeze and pip list —format freeze is that pip freeze does not show the following package management tools by default.
You can display them all by adding the —all option.
By saving the output in freeze format to a text file, you can install packages in a specified version all at once.
In such cases, listing package management tools like pip isn’t necessary, hence pip freeze omits them by default.
Check details of installed packages: pip show
pip show displays detailed information about a given package.
In addition to version information, detailed information such as license and dependency packages is displayed.
$ 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 License: BSD 3-Clause License . Location: /opt/homebrew/lib/python3.11/site-packages Requires: numpy, numpy, python-dateutil, pytz, tzdata Required-by:
Check package version with conda command: conda list
If you have built a Python environment with Anaconda, conda list will list the packages installed in the current virtual environment.
When the environment is not activated, use conda list -n .