07-16-2022, 08:41 AM
8 Best Ways to Check the Package Version in Python
5/5 – (1 vote)
In this article, I’ll show you how to check the version of a Python module (package, library).
These are the eight best ways to check the version of a Python module:
Let’s dive into some examples for each of those next!
Method 1: pip show
To check which version of a given Python library, say, is installed, use or . For example, to check the version of your NumPyinstallation, run in your CMD/Powershell (Windows), or terminal (macOS/Linux/Ubuntu).
This will work if your pip installation is version 1.3 or higher—which is likely to hold in your case because pip 1.3 was released a decade ago in 2013!!
Here’s an example in my Windows Powershell for NumPy: I’ve highlighted the line that shows that my package version is:
In some instances, this will not work—depending on your environment. In this case, try those commands before giving up:
Of course, replace “” with your particular package name.
Method 2: pip list
To check the versions of all installed packages, use and locate the version of your particular package in the output list of package versions sorted alphabetically.
This will work if your pip installation is version 1.3 or higher.
Here’s an example in my Windows Powershell, I’ve highlighted the line that shows that my package version is 1.21.0:
In some instances, this will not work—depending on your environment. Then try those commands before giving up:
Method 3: pip list + findstr on Windows
To check the versions of a single package on Windows, you can chain with using the CMD or Powershell command: to locate the version of your particular package in the output list of package versions automatically.
Here’s an example for:
Method 4: Library.__version__ Attribute
To check your package installation in your Python script, you can also use the attribute of the particular library . Not all packages provide this attribute but as it is recommended by PEP, it’ll work for most libraries.
Here’s the code:
Here’s an excerpt from the PEP 8 docs mentioning the attribute.
“PEP 8 describes the use of a module attribute called for recording “Subversion, CVS, or RCS” version strings using keyword expansion. In the PEP author’s own email archives, the earliest example of the use of an module attribute by independent module developers dates back to 1995.”
Method 5: importlib.metadata.version
The library provides a general way to check the package version in your Python script via for library . This returns a string representation of the specific version. For example, returns in my current environment.
Here’s the code:
Method 6: conda list
If you have created your Python environment with Anaconda, you can use to list all packages installed in your (virtual) environment. Optionally, you can add a regular expression using the syntax conda list regex to list only packages matching a certain pattern.
How to list all packages in the current environment?
How to list all packages installed into the environment?
Regex: How to list all packages starting with?
Regex: How to list all packages starting with or ?
Method 7: pip freeze
The command without any option lists all installed Python packages in your environment in alphabetically order (ignoring UPPERCASE or lowercase). You can spot your specific package if it is installed in the environment.
Output from my local Windows environment with PowerShell (strange packages I know) ;):
For example, I have the Python package installed with version .
You can modify or exclude specific packages using the options provided in this screenshot:
source
Method 8: pip freeze + grep on Linux/Ubuntu/macOS
To check the versions of a single package on Linux/Ubuntu/macOS, you can chain with using the CMD or Powershell command: to programmatically locate the version of your particular package in the output list of package versions.
Here’s an example for:
Related Questions
Check Package Version Python
How to check package version in Python?
To check which version of a given Python package is installed, use. For example, to check the version of your NumPyinstallation, run in your CMD/Powershell (Windows), or terminal (macOS/Linux/Ubuntu).
Check Package Version Linux
How to check my package version in Linux?
To check which version of a given Python package is installed, use. For example, to check the version of your NumPyinstallation, run in your Linux terminal.
Check Package Version Ubuntu
How to check my package version in Ubuntu?
To check which version of a given Python package is installed, use. For example, to check the version of your NumPyinstallation, run in your Ubuntu terminal/shall/bash.
Check Package Version Windows
How to check package version on Windows?
To check which version of a given Python package is installed, use. For example, to check the version of your NumPyinstallation, run in your Windows CMD, command line, or PowerShell.
Check Package Version Mac
How to check package version on macOS?
To check which version of a given Python package is installed, use. For example, to check the version of your NumPyinstallation, run in your macOS terminal.
Check Package Version Jupyter Notebook
How to check package version in your Jupyter Notebook?
To check which version of a given Python package is installed, add the line to your notebook cell where you want to check. Notice the exclamation mark prefix that allows you to run commands in your Python script cell. For example, to check the version of your NumPyinstallation, run in your macOS terminal.
For example, this is a screenshot on how this looks for numpy in a Jupyter Notebook:
![[Image: image-63-1024x264.png]](https://blog.finxter.com/wp-content/uploads/2022/07/image-63-1024x264.png)
Check Package Version Terminal
How to check package version in my terminal?
To check which version of a given Python package is installed, use. For example, to check the version of your NumPyinstallation, run in your terminal.
Check Package Version Conda/Anaconda
How to check package version in my conda installation?
Use to list version information about the specific package installed in your (virtual) environment.
Check Package Version with PIP
How to check package version with pip?
You can use multiple commands to check the package version with PIP such as, , , and .
Check Package Version in VSCode or PyCharm
How to check package version in VSCode or PyCharm?
Integrated Development Environments (IDEs) such as VSCode or PyCharm provide a built-in terminal where you can run to check the current version of in the specific environment you’re running the command in.
You can type any of those commands in your IDE terminal like so:
![[Image: image-64-1024x560.png]](https://blog.finxter.com/wp-content/uploads/2022/07/image-64-1024x560.png)
Summary
In this article, you’ve learned those best ways to check a Python package version:
Thanks for giving us your valued attention — we’re grateful to have you here!![[Image: 1f642.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f642.png)
Programmer Humor
There are only 10 kinds of people in this world: those who know binary and those who don’t.
![[Image: 1f469.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f469.png)
![[Image: 1f9d4-200d-2642-fe0f.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f9d4-200d-2642-fe0f.png)
~~~
There are 10 types of people in the world. Those who understand trinary, those who don’t, and those who mistake it for binary.
![[Image: 1f469.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f469.png)
![[Image: 1f9d4-200d-2642-fe0f.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f9d4-200d-2642-fe0f.png)
5/5 – (1 vote)
In this article, I’ll show you how to check the version of a Python module (package, library).
These are the eight best ways to check the version of a Python module:
- Method 1: Code:
pip show my_package
- Method 2: Code:
pip list
- Method 3: Code:
pip list | findstr my_package
- Method 4: Code:
my_package.__version__
- Method 5: Code:
importlib.metadata.version
- Method 6: Code:
conda list
- Method 7: Code:
pip freeze
- Method 8: Code:
pip freeze | grep my_package
Let’s dive into some examples for each of those next!
Method 1: pip show
To check which version of a given Python library, say
Code:
xyzCode:
pip show xyzCode:
pip3 show xyzCode:
pip show numpyThis will work if your pip installation is version 1.3 or higher—which is likely to hold in your case because pip 1.3 was released a decade ago in 2013!!
Here’s an example in my Windows Powershell for NumPy: I’ve highlighted the line that shows that my package version is
Code:
1.21.0Code:
PS C:\Users\xcent> pip show numpy
Name: numpy
Version: 1.21.0
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: c:\users\xcent\appdata\local\programs\python\python39\lib\site-packages
Requires:
Required-by: pandas, matplotlibIn some instances, this will not work—depending on your environment. In this case, try those commands before giving up:
Code:
python -m pip show numpy
python3 -m pip show numpy
py -m pip show numpy
pip3 show numpyOf course, replace “
Code:
numpyMethod 2: pip list
To check the versions of all installed packages, use
Code:
pip listThis will work if your pip installation is version 1.3 or higher.
Here’s an example in my Windows Powershell, I’ve highlighted the line that shows that my package version is 1.21.0:
Code:
PS C:\Users\xcent> pip list
Package Version
--------------- ---------
beautifulsoup4 4.9.3
bs4 0.0.1
certifi 2021.5.30
chardet 4.0.0
cycler 0.10.0
idna 2.10
kiwisolver 1.3.1
matplotlib 3.4.2
mss 6.1.0
numpy 1.21.0
pandas 1.3.1
Pillow 8.3.0
pip 21.1.1
pyparsing 2.4.7
python-dateutil 2.8.1
pytz 2021.1
requests 2.25.1
setuptools 56.0.0
six 1.16.0
soupsieve 2.2.1
urllib3 1.26.6In some instances, this will not work—depending on your environment. Then try those commands before giving up:
Code:
python -m pip list
python3 -m pip list
py -m pip list
pip3 listTo check the versions of a single package on Windows, you can chain
Code:
pip listCode:
findstr xyzCode:
pip3 list | findstr numpyCode:
xyzHere’s an example for
Code:
numpyCode:
pip3 list | findstr numpy 1.21.0To check your package installation in your Python script, you can also use the
Code:
xyz.__version__Code:
xyzHere’s the code:
Code:
import numpy
print(numpy.__version__)
# 1.21.0Here’s an excerpt from the PEP 8 docs mentioning the
Code:
__version__“PEP 8 describes the use of a module attribute called
Code:
__version__Code:
__version__Method 5: importlib.metadata.version
The
Code:
importlib.metadataCode:
importlib.metadata.version('xyz')Code:
xyzCode:
importlib.metadata.version('numpy')Code:
1.21.0Here’s the code:
Code:
import importlib.metadata
print(importlib.metadata.version('numpy'))
# 1.21.0If you have created your Python environment with Anaconda, you can use
Code:
conda listHow to list all packages in the current environment?
Code:
conda listHow to list all packages installed into the environment
Code:
'xyz'Code:
conda list -n xyzRegex: How to list all packages starting with
Code:
'py'Code:
conda list '^py'Regex: How to list all packages starting with
Code:
'py'Code:
'code'Code:
conda list '^(py|code)'The
Code:
pip freezeCode:
pip freezeOutput from my local Windows environment with PowerShell (strange packages I know) ;):
Code:
PS C:\Users\xcent> pip freeze
asn1crypto==1.5.1
et-xmlfile==1.1.0
openpyxl==3.0.10For example, I have the Python package
Code:
openpyxlCode:
3.0.10You can modify or exclude specific packages using the options provided in this screenshot:
sourceMethod 8: pip freeze + grep on Linux/Ubuntu/macOS
To check the versions of a single package on Linux/Ubuntu/macOS, you can chain
Code:
pip freezeCode:
grep xyzCode:
pip freeze | grep xyzCode:
xyzHere’s an example for
Code:
numpyCode:
pip freeze | grep scikit-learn
scikit-learn==0.17.1Check Package Version Python
How to check package version in Python?
To check which version of a given Python package is installed, use
Code:
pip show my_packageCode:
pip show numpyCode:
pip show my_packageHow to check my package version in Linux?
To check which version of a given Python package is installed, use
Code:
pip show my_packageCode:
pip show numpyCode:
pip show my_packageHow to check my package version in Ubuntu?
To check which version of a given Python package is installed, use
Code:
pip show my_packageCode:
pip show numpyCode:
pip show my_packageHow to check package version on Windows?
To check which version of a given Python package is installed, use
Code:
pip show my_packageCode:
pip show numpyCode:
pip show my_packageHow to check package version on macOS?
To check which version of a given Python package is installed, use
Code:
pip show my_packageCode:
pip show numpyCode:
pip show my_packageHow to check package version in your Jupyter Notebook?
To check which version of a given Python package is installed, add the line
Code:
!pip show my_packageCode:
!Code:
!pip show numpyCode:
!pip show my_packageFor example, this is a screenshot on how this looks for numpy in a Jupyter Notebook:
![[Image: image-63-1024x264.png]](https://blog.finxter.com/wp-content/uploads/2022/07/image-63-1024x264.png)
Check Package Version Terminal
How to check package version in my terminal?
To check which version of a given Python package is installed, use
Code:
pip show my_packageCode:
pip show numpyCode:
pip show my_packageHow to check package version in my conda installation?
Use
Code:
conda list 'my_package'Code:
conda list 'my_package'How to check package version with pip?
You can use multiple commands to check the package version with PIP such as
Code:
pip show my_packageCode:
pip listCode:
pip freezeCode:
pip listCode:
pip show my_package
pip list
pip freeze
pip listHow to check package version in VSCode or PyCharm?
Integrated Development Environments (IDEs) such as VSCode or PyCharm provide a built-in terminal where you can run
Code:
pip show my_packageCode:
my_packageCode:
pip show my_package
pip list
pip freezeYou can type any of those commands in your IDE terminal like so:
![[Image: image-64-1024x560.png]](https://blog.finxter.com/wp-content/uploads/2022/07/image-64-1024x560.png)
Summary
In this article, you’ve learned those best ways to check a Python package version:
- Method 1: Code:
pip show my_package
- Method 2: Code:
pip list
- Method 3: Code:
pip list | findstr my_package
- Method 4: Code:
my_package.__version__
- Method 5: Code:
importlib.metadata.version
- Method 6: Code:
conda list
- Method 7: Code:
pip freeze
- Method 8: Code:
pip freeze | grep my_package
Thanks for giving us your valued attention — we’re grateful to have you here!
![[Image: 1f642.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f642.png)
Programmer Humor
There are only 10 kinds of people in this world: those who know binary and those who don’t.
![[Image: 1f469.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f469.png)
![[Image: 1f9d4-200d-2642-fe0f.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f9d4-200d-2642-fe0f.png)
~~~
There are 10 types of people in the world. Those who understand trinary, those who don’t, and those who mistake it for binary.
![[Image: 1f469.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f469.png)
![[Image: 1f9d4-200d-2642-fe0f.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f9d4-200d-2642-fe0f.png)

