0
0
NumpyHow-ToBeginner ยท 3 min read

How to Check NumPy Version Installed in Your Environment

You can check the installed numpy version by running numpy.__version__ in Python. Alternatively, use pip show numpy in your command line to see the version details.
๐Ÿ“

Syntax

To check the NumPy version in Python, use the attribute __version__ from the numpy module.

  • numpy.__version__: Returns the version string of the installed NumPy package.
python
import numpy
print(numpy.__version__)
Output
1.24.3
๐Ÿ’ป

Example

This example shows how to import NumPy and print its version. It helps confirm which version is currently installed in your Python environment.

python
import numpy
version = numpy.__version__
print(f"Installed NumPy version: {version}")
Output
Installed NumPy version: 1.24.3
โš ๏ธ

Common Pitfalls

Sometimes users try to check the version without importing NumPy first, which causes an error. Also, using pip list might show multiple versions if you have several Python environments.

Always ensure you run the version check in the same environment where your code runs.

python
try:
    print(numpy.__version__)
except NameError:
    print("Error: NumPy is not imported. Please import numpy first.")

# Correct way:
import numpy
print(numpy.__version__)
Output
Error: NumPy is not imported. Please import numpy first. 1.24.3
๐Ÿ“Š

Quick Reference

MethodDescriptionExample Command
Python attributeCheck version inside Python codeimport numpy; print(numpy.__version__)
Command line pipCheck version via pip in terminalpip show numpy
Command line pip listList all installed packages with versionspip list | grep numpy
โœ…

Key Takeaways

Use numpy.__version__ in Python to get the installed NumPy version.
Always import NumPy before checking its version to avoid errors.
You can also check the version from the command line using pip show numpy.
Make sure you check the version in the correct Python environment.
Using pip list helps see all installed packages and their versions.