How to check NumPy Version in Python?

In this article, we will discuss how to check the version of numpy in python.

Table Of Contents

What is numpy?

numpy stands for numeric python, and used to work on the arrays. It is a python module that can be imported directly.

There are multiple ways to check the version of numpy. Lets discuss all the methods one by one with proper approach and a working code example.

Using the version object

The version is the object available in python which is used to check the version of any kind of module. So by using this, we can check the version of the numpy module. But, before checking the version, we have to import the numpy module. We can import by using the import keyword.

Syntax:

numpy.version.version

Example:

Let’s check the version of numpy module in our working environment.

import numpy

# Check the version
ver = numpy.version.version

print(ver)

Output:

1.21.6

Our numpy module version is 1.21.6

We can also check the version with version method using the following syntax:

numpy.__version__

Example:

#import the numpy module
import numpy

#check the version
print(numpy.__version__)

Output:

1.21.6

Check numpy version using pip

The pip is a command used to install a module in python.

Syntax to install:

pip install module_name

Where, module_name is the module to be installed. For example, we can also install the numpy module using,

pip install numpy

Using pip, we can get information about any kind of module. In pip, there are different ways to get the version of numpy. Let’s discuss them one by one.

Check numpy version using show with pip

Syntax:

pip show module_name

Where, module_name is the name of the module, Here it is numpy. The show used with pip will return the following

  1. Name: Refers to the module name
  2. Version: module version
  3. Summary: Module definition
  4. Home-page: Official website of the module
  5. Author: Author name of the module
  6. Author-email: Author email address
  7. License: module license
  8. Location: Location in which module has resided
  9. Requires: return list of other modules that need/uses the current module.

Example:

In this example, we will use show with pip to get the numpy details.

pip 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: None
License: BSD
Location: /usr/local/lib/python3.7/dist-packages
Requires: 
Required-by: yellowbrick, xgboost, xarray, xarray-einstats, wordcloud, torchvision, torchtext, tifffile, thinc, Theano-PyMC, tensorflow, tensorflow-probability, tensorflow-hub, tensorflow-datasets, tensorboard, tables, statsmodels, spacy, sklearn-pandas, seaborn, scs, scipy, scikit-learn, scikit-image, resampy, qdldl, PyWavelets, python-louvain, pystan, pysndfile, pymc3, pyerfa, pyemd, pycocotools, pyarrow, plotnine, patsy, pandas, osqp, opt-einsum, opencv-python, opencv-contrib-python, numexpr, numba, nibabel, netCDF4, moviepy, mlxtend, mizani, missingno, matplotlib, matplotlib-venn, lightgbm, librosa, Keras-Preprocessing, kapre, jpeg4py, jaxlib, jax, imgaug, imbalanced-learn, imageio, hyperopt, holoviews, h5py, gym, gensim, folium, fix-yahoo-finance, fbprophet, fastdtw, fastai, fa2, ecos, daft, cvxpy, cufflinks, cmdstanpy, cftime, Bottleneck, bokeh, blis, autograd, atari-py, astropy, arviz, altair, albumentations

Check numpy version using list with pip

Syntax:

pip list

The list will return all module names followed by the module version.

Example:

pip list

Output:

opt-einsum                    3.3.0
osqp                          0.6.2.post0
packaging                     21.3
palettable                    3.3.0
pandas                        1.3.5
pandas-datareader             0.9.0
pandas-gbq                    0.13.3
pandas-profiling              1.4.1
pandocfilters                 1.5.0
panel                         0.12.1
param                         1.12.1
parso                         0.8.3
pathlib                       1.0.1
patsy                         0.5.2
pep517                        0.12.0
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        7.1.2
pip                           21.1.3
pip-tools                     6.2.0
plac                          1.1.3
plotly                        5.5.0
plotnine                      0.6.0
pluggy                        0.7.1
pooch                         1.6.0
portpicker                    1.3.9
prefetch-generator            1.0.1
preshed                       3.0.6
prettytable                   3.3.0
progressbar2                  3.38.0
prometheus-client             0.14.1
promise                       2.3
prompt-toolkit                1.0.18
protobuf                      3.17.3
psutil                        5.4.8
psycopg2                      2.7.6.1
ptyprocess                    0.7.0
py                            1.11.0
pyarrow                       6.0.1
pyasn1                        0.4.8
pyasn1-modules                0.2.8
pycocotools                   2.0.4
pycparser                     2.21
pyct                          0.4.8
pydata-google-auth            1.4.0
pydot                         1.3.0
pydot-ng                      2.0.0
pydotplus                     2.0.2
PyDrive                       1.3.1
pyemd                         0.5.1
pyerfa                        2.0.0.1
pyglet                        1.5.0
Pygments                      2.6.1
pygobject                     3.26.1
pymc3                         3.11.4
PyMeeus                       0.5.11
pymongo                       4.1.1
pymystem3                     0.2.0
PyOpenGL                      3.1.6
pyparsing                     3.0.9
pyrsistent                    0.18.1
pysndfile                     1.3.8
PySocks                       1.7.1
pystan                        2.19.1.1
pytest                        3.6.4
python-apt                    0.0.0
python-chess                  0.23.11
python-dateutil               2.8.2
python-louvain                0.16
python-slugify                6.1.2
python-utils                  3.2.2
pytz                          2022.1
pyviz-comms                   2.2.0
PyWavelets                    1.3.0
PyYAML                        3.13
pyzmq                         22.3.0
qdldl                         0.1.5.post2
qtconsole                     5.3.0
QtPy                          2.1.0
regex                         2019.12.20
requests                      2.23.0
requests-oauthlib             1.3.1
resampy                       0.2.2
rpy2                          3.4.5
rsa                           4.8
scikit-image                  0.18.3
scikit-learn                  1.0.2
scipy                         1.4.1
screen-resolution-extra       0.0.0
scs                           3.2.0
seaborn                       0.11.2
semver                        2.13.0
Send2Trash                    1.8.0
setuptools                    57.4.0
setuptools-git                1.2
Shapely                       1.8.2
simplegeneric                 0.8.1
six                           1.15.0
sklearn                       0.0
sklearn-pandas                1.8.0
smart-open                    6.0.0
snowballstemmer               2.2.0
sortedcontainers              2.4.0
SoundFile                     0.10.3.post1
soupsieve                     2.3.2.post1
spacy                         2.2.4
Sphinx                        1.8.6
sphinxcontrib-serializinghtml 1.1.5
sphinxcontrib-websupport      1.2.4
SQLAlchemy                    1.4.36
sqlparse                      0.4.2
srsly                         1.0.5
statsmodels                   0.10.2
sympy                         1.7.1
tables                        3.7.0
tabulate                      0.8.9
tblib                         1.7.0
tenacity                      8.0.1
tensorboard                   2.8.0
tensorboard-data-server       0.6.1
tensorboard-plugin-wit        1.8.1
tensorflow                    2.8.0+zzzcolab20220506162203
tensorflow-datasets           4.0.1
tensorflow-estimator          2.8.0
tensorflow-gcs-config         2.8.0
tensorflow-hub                0.12.0
tensorflow-io-gcs-filesystem  0.25.0
tensorflow-metadata           1.8.0
tensorflow-probability        0.16.0
termcolor                     1.1.0
terminado                     0.13.3
testpath                      0.6.0
text-unidecode                1.3
textblob                      0.15.3
Theano-PyMC                   1.1.2
thinc                         7.4.0
threadpoolctl                 3.1.0
tifffile                      2021.11.2
tinycss2                      1.1.1
tomli                         2.0.1
toolz                         0.11.2
torch                         1.11.0+cu113
torchaudio                    0.11.0+cu113
torchsummary                  1.5.1
torchtext                     0.12.0
torchvision                   0.12.0+cu113
tornado                       5.1.1
tqdm                          4.64.0
traitlets                     5.1.1
tweepy                        3.10.0
typeguard                     2.7.1
typing-extensions             4.2.0
tzlocal                       1.5.1
uritemplate                   3.0.1
urllib3                       1.24.3
vega-datasets                 0.9.0
wasabi                        0.9.1
wcwidth                       0.2.5
webencodings                  0.5.1
Werkzeug                      1.0.1
wheel                         0.37.1
widgetsnbextension            3.6.0
wordcloud                     1.5.0
wrapt                         1.14.1
xarray                        0.20.2
xarray-einstats               0.2.2
xgboost                       0.90
xkit                          0.0.0
xlrd                          1.1.0
xlwt                          1.3.0
yellowbrick                   1.4
zict                          2.2.0
zipp                          3.8.0
[95]
0s

From the above list, we can check that the numpy version is 1.21.6.

Check numpy version using FINDSTR with pip list

If we want to get only numpy module version from the list in Command Prompt. Then the FINDSTR is used to find the string i.e numpy module from the list.

Syntax:

pip list | FINDSTR numpy

Output:

numpy           1.21.4

The version of the numpy module is 1.21.4.

Check numpy version using numexpr module

The numexpr module is used to evaluate numerical expressions performed on the numpy arrays. The print_versions() in this module is used to display the numpy version.

Syntax:

numexpr.print_versions()

Example:

import numexpr

# get the numpy the version
ver = numexpr.print_versions()

# display the version
print(ver)

Output:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Numexpr version:   2.8.1
NumPy version:     1.21.6
Python version:    3.7.13 (default, Apr 24 2022, 01:04:09) 
[GCC 7.5.0]
Platform:          linux-x86_64-#1 SMP Sun Apr 24 10:03:06 PDT 2022
CPU vendor:        
CPU model:         
CPU clock speed:    MHz
VML available?     False
Number of threads used by default: 2 (out of 2 detected cores)
Maximum number of threads: 64
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
None

Check numpy version using the pkg_resources module

This package helps to find, utilize and provide tools for python packages. The get_distribution() method will return the module version along with version() method.

Syntax:

pkg_resources.get_distribution('module_name').version

where module_name is the name of the module. here it is numpy.

It will return only the version.

Example:

import pkg_resources

# Get the numpy version
ver = pkg_resources.get_distribution('numpy').version

# Display the numpy version
print(ver)

Output:

1.21.6

The numpy version is 1.21.6

Check numpy version using importlib_metadata module

The importlib_metadata provides the version method, to return the module version in python.

Syntax:

importlib_metadata.version('module_name')

where module_name is the name of the module. Here it is numpy. It will return only the version.

Example:

from importlib_metadata import version

# Display the numpy version
print(version('numpy'))

Output:

1.21.6

The numpy version is 1.21.6

Summary

Great! you made it, we discussed 10 approaches to get the numpy version running in our python environment. Based on the python compiler and pip version, you can check the version of any module, Happy learning.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top