How to Check Numpy Version in Your Python Script?
Check numpy Version: This article will detail the different methods to check the version of NumPy installed on your Python environment.
Numpy Python Module
The Python module numpy is a very powerful mathematical library that is used to perform various analyses and many packages are dependent on numpy (such as the Pandas module). It is often used by data analysts or data scientists because it can be integrated with a large number of databases.
In many cases, it will be necessary to check the numpy version to avoid possible conflicts that many packages depend on.
This article will explain how to determine which version of numpy is installed on your machine.
Check numpy Version With __version__ Attribut
As in a large majority of python packages, it is possible to get the version of numpy with the __version__ attribute.
# __version__ attribut import numpy as np print(np.__version__)
Get detailed information using
Another way to check the NumPy version running in your script is to use the np.version.version attribute
To print the version, simply use the print() function. Here is the code that does it:
# np.version.version attribut import numpy as np print(np.version.version)
numpy.version can also provide you with other information about your numpy version such as :
# np.version.version attribut import numpy as np print("Short Version: " + np.version.short_version) print("Full Version: " + np.version.full_version) print("Git Revision: " + np.version.git_revision) print("Release Version: " + str(np.version.release))
Short Version: 1.21.2 Full Version: 1.21.2 Git Revision: 2fe48d2d98a85c8ea3f3d5caffd952ea69e99335 Release Version: True
We can see that in the previous example, the attributes version, short_version and full_version contain the same value.
Check numpy Version using PIP
pip is the package installer for Python. It is often used to install, upgrade or to get the version of a package.
So we can also use the pip show command to get information (including its version.) about a package.
Here is how to proceed for the numpy module:
(venv) C:\Users\Pycharm\project>pip show numpy Name: numpy Version: 1.21.2 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\pycharm\project\venv\lib\site-packages Requires: Required-by: pandas
You can also see the packages that are dependent on numpy.
The pip list command allows to list all the packages installed on the python environment and their version:
(venv) C:\Users\Pycharm\project>pip list Package Version ------------------ --------- certifi 2021.5.30 charset-normalizer 2.0.4 idna 3.2 numpy 1.21.2 pandas 1.3.2
This tutorial explained how to get the version of numpy currently installed on your python environment. If you have any problems installing NumPy, don’t hesitate to tell me in comments !