×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

How to Check Version of Python Modules

Last Updated : April 28, 2025

One of the ideal ways of managing Python libraries is using PIP (Python Package Manager). PIP not only helps in installing libraries but also provides an option to verify the version of installed modules. In this chapter, we will explore different methods to check the version of Python modules installed in your environment.

Approach 1: Using pip freeze Command

The simplest way to check the version of installed Python modules is by using the pip freeze command. This command returns a list of all installed modules along with their versions.

Example

This command lists all installed modules and their corresponding versions in your environment. For example:

# Run the command to check installed modules and their versions
pip freeze

The output of the above command might look like:

notebook==6.0.2
numpy==1.17.2
openpyxl==3.0.2
pandas==0.25.3
pandocfilters==1.4.2
parso==0.5.2
pexpect==4.7.0
pickleshare==0.7.5
prometheus-client==0.7.1
prompt-toolkit==3.0.2
ptyprocess==0.6.0
Pygments==2.5.2
pynb==0.1.36
pyrsistent==0.15.6
python-dateutil==2.8.1
pytz==2019.3
pyzmq==18.1.1
qtconsole==4.6.0
Send2Trash==1.5.0
six==1.13.0
soupsieve==1.9.5
SQLAlchemy==1.3.12
terminado==0.8.3
testpath==0.4.4
tornado==6.0.3
traitlets==4.3.3
wcwidth==0.1.8
webencodings==0.5.1
widgetsnbextension==3.5.1

If you want to verify the version of a specific module, you can use the following command:

Example

# Run the command to check the version 
# of a specific module, e.g., pandas
pip freeze | grep pandas

The output of the above command would be:

pandas==0.25.3

Approach 2: Using the __version__ Attribute

Another method to check the version of installed Python modules is by using the __version__ attribute. This method requires you to write a small Python code.

Example

This code snippet demonstrates how to retrieve the version of the pandas module using its __version__ attribute.

# Import the module 
import pandas as pd

# Print the version of the module
print(pd.__version__)

The output of the above code would be:

0.25.3

Approach 3: Using pip show Command

Another method to check the version of a Python module is by using the pip show command. This provides detailed information about a specific installed package, including its version.

Example

# Run the command to check details of a 
# specific module, e.g., pandas
pip show pandas

The output of this command provides detailed information about the installed module, including the version:

Name: pandas
Version: 0.25.3
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: http://pandas.pydata.org
Author: The Pandas Development Team
Author-email: [email protected]
License: BSD
Location: /path/to/python/site-packages
Requires: numpy, pytz, python-dateutil
Required-by: 

Approach 4: Using conda list Command (If Using Anaconda)

If you are using the Anaconda distribution of Python, you can use the conda list command to see the versions of installed modules in your environment.

Example

# Run the command to list all installed modules 
# and their versions in Anaconda
conda list

The output will be similar to pip freeze, but it lists all modules installed in the current conda environment.

The output of the above command might look like:

# packages in environment at /path/to/anaconda:
#
# Name                    Version                   Build  Channel
pandas                    0.25.3           py37he6710b0_0    defaults
numpy                     1.17.2           py37h19a2e04_0    defaults
scipy                     1.3.1            py37h29ff71b_0    defaults

Approach 5: Using pkg_resources Module

You can also use the pkg_resources module, which is part of the setuptools package, to check the version of an installed module.

Example

This example demonstrates using the pkg_resources.get_distribution() method to retrieve the version of a module.

import pkg_resources

def get_version(module):
    return pkg_resources.get_distribution(module).version

# Check version of pandas
print(get_version("pandas"))

The output of the above code would be:

0.25.3

Exercise

Select the correct option to complete each statement about checking the version of Python modules.

  1. A common way to check a module’s version is by accessing the ___ attribute.
  2. To check the installed packages and their versions from the command line, you can use the ___ command.
  3. Another way to get the version of a package programmatically is by using the ___ module from the standard library (available in Python 3.8+).

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.