Run python -m pip show <package-name> in your terminal to inspect the exact installed version, installation path (Location), and dependencies—or run python -m pip list to view all installed packages and their versions at once inside your active Python environment.
Basic Example
# 1. Recommended: Show detailed metadata including the exact Version line
python -m pip show requests
# Output:
# Name: requests
# Version: 2.32.3
# Summary: Python HTTP for Humans.
# Location: /path/to/.venv/lib/python3.12/site-packages
# ...
# 2. List all installed packages and versions in a clean table
python -m pip list
# 3. Filter for a specific package in a list (Linux/macOS vs. Windows)
python -m pip list | grep -i pandas # Linux / macOS / Git Bash
python -m pip list | findstr /i pandas # Windows Command Prompt / PowerShell
Key Details & Edge Cases
- Always prefer
python -m pipover barepip:- If multiple Python versions or virtual environments exist on your machine, bare
pip show pkgcan query a different environment than thepythoninterpreter you run. Prefixing withpython -m pipguarantees you inspect thesite-packagesdirectory of that exact Python executable.
- If multiple Python versions or virtual environments exist on your machine, bare
- Distribution name vs. import name (
pip showuses the PyPI distribution name):- Pass the package distribution name rather than the Python import name when they differ—for example, run
python -m pip show Pillow(notPIL),python -m pip show scikit-learn(notsklearn), orpython -m pip show beautifulsoup4(notbs4). Note thatpip showis case-insensitive (pillowandPillowboth work).
- Pass the package distribution name rather than the Python import name when they differ—for example, run
- Exit codes when a package is missing:
python -m pip show nonexistent-pkgprintsWARNING: Package(s) not found: nonexistent-pkgand exits with status code1, making it reliable for shell scripts and CI checks.
- Machine-readable JSON output (
pip list --format=json):- When parsing installed versions in automation scripts, run
python -m pip list --format=json(orpython -m pip inspectin modernpip22.2+) instead of scraping human-formatted text tables.
- When parsing installed versions in automation scripts, run
- Checking the version inside Python code (
importlib.metadata):- If you need the installed version programmatically at runtime without spawning a subprocess, use Python’s standard library
importlib.metadata.version("requests")(which works even for packages that lack a__version__attribute).
- If you need the installed version programmatically at runtime without spawning a subprocess, use Python’s standard library
Comparison of pip Version Inspection Commands
| Command | Output Format | Checks Single or All Packages? | Shows Install Location & Dependencies? | Best Used When |
|---|---|---|---|---|
python -m pip show <pkg> |
Key-value metadata block | Single (or space-separated list) | Yes (Location, Requires, Required-by) |
Verifying a specific package’s exact version and which site-packages folder loaded it. |
python -m pip list |
Aligned two-column table | All installed packages | No (Name + Version only) | Getting an overview of every library installed in the active environment. |
python -m pip list --outdated |
Table (Version vs. Latest) |
Outdated packages only | No | Checking which installed packages have newer releases available on PyPI. |
python -m pip freeze |
package==version lines |
All installed packages | No | Generating exact pinned version pins for requirements.txt or lockfiles. |
python -m pip list --format=json |
JSON array of objects | All installed packages | No | Programmatically parsing package names and versions in CI/CD or automation scripts. |
You must log in or register to comment.
