Python
Pip
Package Management
Programming
Version Control

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.

Introduction

If you need to know which version of a Python package is installed, the most direct answer is python -m pip show package-name. The important detail is using the same Python interpreter that your project actually runs, because package versions are tied to environments, not just to the machine.

Use pip show for One Package

The standard command is:

bash
python -m pip show requests

Typical output looks like this:

text
1Name: requests
2Version: 2.32.3
3Summary: Python HTTP for Humans.
4Location: /path/to/site-packages
5Requires: certifi, charset-normalizer, idna, urllib3

The Version: line is the value most people want, but the Location: line is often just as useful because it tells you which environment the package came from.

Using python -m pip is safer than a bare pip command. It makes sure pip runs under the interpreter you named, which matters if you have multiple Python versions installed.

Use pip list When You Want a Broader View

If you are not sure whether the package is installed at all, or you want to scan the full environment, list packages:

bash
python -m pip list

To narrow the output, combine it with a shell filter:

bash
python -m pip list | grep requests

Or use pip list in freeze format:

bash
python -m pip list --format=freeze | grep '^requests=='

That form is convenient when you want output that resembles a requirements file.

Use pip freeze for Reproducible Environments

pip freeze prints installed distributions pinned to exact versions:

bash
python -m pip freeze | grep '^requests=='

Example output:

text
requests==2.32.3

This is useful when generating dependency snapshots, but it is less descriptive than pip show because it only prints package pins.

Make Sure You Are Checking the Right Environment

This is where many developers get tripped up. You may have:

  • a system Python
  • a virtual environment
  • a Conda environment
  • an IDE-managed interpreter

These can all hold different versions of the same package.

For example:

bash
1python --version
2python -m pip show requests
3which python
4which pip

Those commands help confirm which interpreter and installer you are actually using.

Inside a virtual environment, the right version is usually:

bash
source .venv/bin/activate
python -m pip show requests

On Windows, activation is different, but the idea is the same: activate first, then inspect the package from that environment.

Package Name vs Import Name

Another source of confusion is that the package you install is not always the same as the module you import. For instance, you install beautifulsoup4, but import bs4.

If pip show bs4 fails, try the distribution name instead:

bash
python -m pip show beautifulsoup4

When in doubt, check the project’s installation instructions or inspect your environment with pip list.

A Quick Python-Side Check

If you want to confirm the version from inside the running interpreter, use Python itself:

python
from importlib.metadata import version

print(version("requests"))

This is not a pip command, but it is very useful when debugging inside a running application or notebook.

Common Pitfalls

The biggest pitfall is checking the wrong interpreter. pip show can be completely accurate and still mislead you if it belongs to a different Python installation than the one your app uses.

Another common mistake is searching with the import name instead of the installed distribution name. Those are often, but not always, the same.

People also confuse pip list and pip freeze. list is better for browsing an environment, while freeze is better for exact dependency pins.

Finally, if a package is editable or installed from a local checkout, version output may not tell the whole story. In that case, also inspect the package location.

Summary

  • Use python -m pip show package-name for the clearest single-package version check.
  • Use python -m pip list when you want to browse the whole environment.
  • Use python -m pip freeze when you need pinned versions for reproducibility.
  • Always verify that you are checking the correct Python interpreter or virtual environment.
  • If pip show fails, confirm whether the install name differs from the import name.

Course illustration
Course illustration

All Rights Reserved.