__version__()Function to Find the Version of Numpy Module
importlib.metadataModule to Find the Version of the Numpy Module
pkg_resourcesModule to Find the Version of Numpy Module
pipCommands 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.
__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.
import numpy print(numpy.__version__)
Alternatively, we can also use the
version.version method in a similar way.
import numpy print(numpy.version.version)
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.
from importlib_metadata import version print(version('numpy'))
We can also use the
import_metadata module for older versions of Python.
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.
import pkg_resources print(pkg_resources.get_distribution('numpy').version)
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
pip should be updated for this.
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.