Knowing the version of a Python package is essential for debugging, dependency management, reproducibility, and ensuring compatibility. In this guide, you’ll learn multiple reliable ways to check package versions using both the command line and Python code.

(1) Check single package version - Python > 3.8

from importlib.metadata import version
version('pandas')

result:

'2.0.0.dev2'

(2) Check single package version - pip freeze and grep

pip freeze | grep pandas

result:

pandas==2.0.0.dev2

(3) Check all packages in current environment

pip freeze

1. Python check installed package version

This is the cleanest and most modern method to get the version programmatically:

from importlib.metadata import version

print(version("numpy"))

This works even if the package doesn’t define __version__. This way will check the package version with importlib.metadata (Python 3.8+)

2. Python get current package version

Open a terminal and run:

pip show pandas

This shows detailed metadata including:

  • Package name
  • Version
  • Location
  • Dependencies

This is useful when debugging environments.
Use pip show to Get Version and Package Info

This section shows how to use pip show to get version and package info.

3. List All Installed Packages and Modules

To see every installed package with its version:

pip list

or for Python 3 specifically:

pip3 list

This is great for auditing your environment. ([TechBloat][2])

4. Python find version of package

Many packages expose a version attribute:

import pandas as pd
print(pd.__version__)

This is quick and easy if the package supports __version__.

5. Why To Check Package Versions

  • Reproducibility:
    • Ensures your code runs the same on other machines.
  • Dependency management:
    • Helps avoid conflicting versions.
  • Debugging:
    • Many errors are version related.
  • CI/CD workflows:
    • Useful in automated testing and deployment.

6. Tips for Best Results

  • Always check versions inside your virtual environment to avoid conflicts.
  • Use pip freeze > requirements.txt to lock versions.
  • If a package doesn't expose a version, use metadata (importlib.metadata).

Summary

Method Best For
importlib.metadata.version() Programmatic checks
pip show Detailed package info
pip list Full environment audit
__version__ attribute Quick interactive check

7. Check version of installed python modules

import numpy as np
print(np.__version__)

8. Python get current package version - example

(1) Check single package version - Python > 3.8

from importlib.metadata import version
version('pandas')

result:

'2.0.0.dev2'

(2) Check single package version - pip freeze and grep

pip freeze | grep pandas

result:

pandas==2.0.0.dev2

(3) Check all packages in current environment

pip freeze

(4) Check package version and package details (requirements etc)

!pip show moviepy
!pip show moviepy | grep Version

result of first command is:

Name: moviepy
Version: 2.0.0.dev2
Summary: Video editing with Python
Home-page: https://zulko.github.io/moviepy/
Author: Zulko 2017
Author-email:
License: MIT License
Location: /home/user/Software/Tensorflow/environments/venv38/lib/python3.8/site-packages
Requires: requests, proglog, imageio-ffmpeg, numpy, imageio, decorator
Required-by:

(5) Show current used package version

If you install a new version but the previous one was imported. This will result in displaying which one is currently used.

import pandas
pandas.__version__

result:

'2.0.3'

(5) Install specific pre-release version in Python

pip install 'pandas>=1.0.3' --pre

To check which is the installed version of a given Python package use:

from importlib.metadata import version
version('pandas')

result:

'2.0.0.dev2'

Resource

You can read more about pip install here: