Check NumPy Version in Python

  1. Use the __version__() Function to Find the Version of Numpy Module
  2. Use the importlib.metadata Module to Find the Version of the Numpy Module
  3. Use the pkg_resources Module to Find the Version of Numpy Module
  4. Use of pip Commands to Find the Version of the Numpy Module

The numpy module is used to work with arrays in Python. It has functions and classes which can also be used to perform mathematical and logical operations on these objects.

In this tutorial, we will discuss how to check the version of numpy module.

Use the __version__() Function to Find the Version of Numpy Module

Usually, most of the modules have the __version__() method associated with them, which can return its version. This method is available in the numpy module.

For example,

import numpy
print(numpy.__version__)

Output:

1.16.5

Alternatively, we can also use the version.version method in a similar way.

import numpy 
print(numpy.version.version)

Output:

1.16.5

Use the importlib.metadata Module to Find the Version of the Numpy Module

In Python v3.8 and above, we have the importlib.metadata module, which has the version() function. This function will return the version of the specified module.

For example,

from importlib_metadata import version
print(version('numpy'))

Output:

1.16.5

We can also use the import_metadata module for older versions of Python.

Use the pkg_resources Module to Find the Version of Numpy Module

Below Python 3.8, we can use the get_distribution.version() method from the pkg_resources module to find the version of the numpy module. Note that the string that you pass to the get_distribution method should correspond to the PyPI entry.

For example,

import pkg_resources
print(pkg_resources.get_distribution('numpy').version)

Output:

1.16.5

Use of pip Commands to Find the Version of the Numpy Module

We can use many pip commands to stay up to date. Alternatively, we can use the pip show command to find out details about a specific package that includes its version. For the numpy module, we will use the following command.

pip show numpy

Note that pip should be updated for this.

Another pip command which we can use is the pip list. It shows all the installed packages along with their versions. We can check the version as below.

pip list
Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.