There are multiple ways to check the NumPy version; however, the easiest and PEP8 standard practice is to import numpy and use the numpy.__version__
attribute to get the exact version details.
This guide will look at various ways to get the NumPy version. Let us look at each of the approaches using code examples.
Check the NumPy version using __version__
attribute
The easiest and Pythonic way to get the NumPy version is by using the __version__
attribute. This is the standard way to check the version of any standard Python libraries.
import numpy
print(numpy.__version__)
Output
1.21.6
Get the Detailed Version of NumPy
If you need detailed information on the NumPy version, then we can use np.version
. The version.py
file gets generated using setup.py
when we install the NumPy package, and it holds the version information such as version, short_version, full_version, etc.
import numpy as np
print(np.version.version)
print(np.version.short_version)
print(np.version.full_version)
print(np.version.git_revision)
print(np.version.release)
Output
1.21.6
1.21.6
1.21.6
ef0ec786fd4c7622ad2fa0e54d3881f3b9bbd792
True
Note: The version, short_version, full_version will have the same value. If it's not a release version then the git_revision is added to the version and full_version.
Get the NumPy version using pip3
We can use the pip3
command to get the NumPy version. There are multiple ways to get the NumPy version using the pip command.
The pip3 list
command will list all the packages installed in your system or virtual environment.
pip3 list
Output
numpy 1.21.6
openpyxl 3.0.10
pandas 1.1.5
Instead of listing all the packages, you can find the NumPy package by using the command
>> pip3 list | FINDSTR numpy
numpy 1.21.6
On Linux
$ pip list | grep numpy
numpy 1.21.6
The second approach is to use the pip3 show
command. It will provide complete information(version, author, installation path, license, etc.) on NumPy if installed on your machine or virtual environment.
pip3 show numpy
Output
Name: numpy
Version: 1.21.6
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:
License: BSD
Location: c:\users\m1014107\appdata\local\programs\python\python37\lib\site-packages
Requires:
Required-by: pandas
The third approach is to use pip3 freeze
to get any Python package version without opening the Python shell.
>> pip freeze | FINDSTR 'numpy'
numpy==1.21.6
On Linux
$ pip freeze | grep 'numpy'
numpy==1.21.6
Verify the NumPy version on Anaconda Distribution.
We can get the NumPy version in the Anaconda distribution using the conda
command. Open the Anaconda prompt and type the below command.
conda list numpy
Output
# Name Version Build Channel
numpy 1.21.6 py38h34a8a5c_0
numpy-base 1.21.6 py38haf7ebc8_0
numpydoc 1.1.6 pyhd3eb1b0_1
conda list | grep numpy
Output
numpy 1.21.6 py38h7241aed_0
numpy-base 1.21.6 py38h6575580_1
numpydoc 1.1.6 py_0
Print the NumPy version in Command Line
The other alternate way is to use the command line and print the NumPy version, as shown below.
python3 -c "import numpy; print(numpy.__version__)"
python -c "import numpy; print(numpy.__version__)"
Output
1.21.6
Conclusion
There are multiple ways to check the NumPy version; the Pythonic and PEP8 standard ways are to use the numpy.__version__
attribute. Alternatively, we can also use the pip3
command to get the Python version.