Find which version of package is installed with pip
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Understanding Package Versioning with pip
Python’s package manager, pip, is an indispensable tool for installing and managing Python packages. When working with multiple packages, especially in complex projects, it's crucial to know which specific versions are installed. This helps ensure compatibility and reliability across development and production environments. Here's a comprehensive guide on how to find out which version of a package is installed using pip.
Checking Installed Package Versions
There are several ways to determine the version of a package installed via pip. Below are some common methods:
Method 1: Using pip show
The simplest way to check the version of an installed package is by using the pip show command. This command displays detailed information about the package, including its version.
Example:
This command will return an output like:
Method 2: Using pip list
The pip list command shows all installed packages along with their versions. This is particularly useful if you want to see all packages at once.
Example Output:
Method 3: Using Python Code
You can also check the version of a package directly within a Python script or interactive shell. This approach is useful for verifying versions dynamically within your codebase.
Example:
This should output:
Enhancements with pip freeze
The pip freeze command outputs installed packages in a format that allows easy installation in other environments using a requirements file.
Example Output:
You can direct the output of pip freeze to a requirements.txt file:
Comparing with Available Versions
Once you know which version is installed, you may want to compare it with available versions to see if an update is needed.
Method 1: Using pip install
To see all available versions of a package, use the pip install command with the package name followed by ==.
Example:
This will list available versions of numpy:
Summarized Key Points
Below is a table summarizing the methods discussed:
| Command | Description | Use Case |
pip show | Displays detailed information about a package, including its version. | To check a single package version. |
pip list | Lists all installed packages and their versions. | To get an overview of all installed packages. |
| Python Script | Access version via package_name.__version__. | To dynamically check a package version within a script. |
pip freeze | Formats installed packages for replication in other environments. | To create requirements.txt file. |
Additional Tools and Libraries
- virtualenv: Create isolated Python environments to manage package dependencies.
- conda: An alternative package manager which can also provide detailed package information and manage environments.
- pipdeptree: A command-line utility for displaying installed packages in a tree structure which shows dependencies and versions.
Conclusion
Understanding which versions of packages are installed can help maintain the stability and compatibility of Python applications. By using tools like pip show, pip list, and pip freeze, you can efficiently manage package versions. Being aware of these capabilities enhances software reliability and facilitates smooth transitions between various development phases.

