Numpy is a powerful mathematical library that can be used as an efficient multi-dimensional container of generic data. Arbitrary data types can be defined. The Numpy library allows seamless and speedy integration with various databases. If you have not installed Numpy, check out the how to install numpy article. After installing, we need to check the version of Numpy.
How to check the Numpy version
To check a numpy version, write the numpy.__version__ code and run the file. It will return the current version of numpy installed on your machine. There are other approaches too that can help you find the numpy version.
- Use the pip list or pip3 list command.
- From the command line type: python3 -c “import numpy; print(numpy.__version__)”
- From command line type: pip3 freeze | grep ‘numpy’ or pip freeze | grep ‘numpy‘
- From command line type: pip3 show numpy or pip show numpy
Check Numpy version using numpy._version_
Create a file called app.py and write the following two lines of code inside that file.
# app.py import numpy print(numpy.__version__)
Output
python3 app.py 1.18.3
The latest version at the time of writing this tutorial is 1.18.3. Yours might be the oldest or latest, depending on your machine’s installation time.
Getting numpy version using pip3 list command
You can use the following command to list the packages, and if Numpy is installed in your system, it will appear with its version. For example, if you are using Python3, then you can use the following command.
pip3 list
See the output.
pip3 list numpy 1.18.3 oauthlib 3.1.0 opt-einsum 3.2.1 pandas 1.0.3 pip 20.1
If you are using Python 2 or Python, you can use the following command.
pip list
Print Numpy version
We can also print the Numpy version in the command line. Type the following command.
python3 -c "import numpy; print(numpy.__version__)"
See the output.
python3 -c "import numpy; print(numpy.__version__)" 1.18.3
If you are using Python 2.x, you can use the following command.
python -c "import numpy; print(numpy.__version__)"
Using the grep command to get the numpy version
Type the following command.
pip3 freeze | grep 'numpy'
See the output.
pip3 freeze | grep 'numpy' numpy==1.18.3
If you are using Python 2.x, then use the following command.
pip freeze | grep 'numpy'
Using pip3 show command
Type the following command.
pip3 show numpy
See the output
pip3 show numpy Name: numpy Version: 1.18.3 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: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages Requires: Required-by: tensorflow, tensorboard, opt-einsum, Keras-Preprocessing, h5py, scipy, scikit-learn, pandas, matplotlib
Check the Numpy version on Anaconda Distribution
To check a numpy version on Anaconda navigator, use the command conda list | grep numpy command.
conda list | grep numpy
See the output.
conda list | grep numpy numpy 1.18.1 py37h7241aed_0 numpy-base 1.18.1 py37h6575580_1 numpydoc 0.9.2 py_0
Conclusion
All of the above methods are useful for checking the Numpy version on Mac, Linux, and Windows. That’s it.