pip freeze, list & show
Once packages are in an environment, pip gives you several ways to look at them. They all read the same thing, the *.dist-info folders in site-packages, but they answer different questions: what's installed? (list), how do I reproduce this? (freeze), why is this here? (show), and is it consistent? (check).
| Command | Answers | Typical use |
|---|---|---|
pip list |
name and version of everything installed | a quick look; --outdated, --not-required, --format=json |
pip freeze |
the same, as name==version lines |
writing a crude lockfile: pip freeze > requirements.txt |
pip show NAME |
metadata, location, what it requires and what requires it | "why is this package here?" |
pip show -f NAME |
plus every installed file | "which package owns this file?" |
pip check |
do installed packages' requirements still hold? | after manual installs, in CI |
pip inspect |
everything, as JSON | tooling |
list and freeze
python3 -m venv .venv && . .venv/bin/activate
pip install -q requests==2.31.0 rich==13.9.4
echo "--- pip list"
pip list
echo "--- only what nobody depends on (what you asked for)"
pip list --not-required
echo "--- newer versions on the index"
pip list --outdated
echo "--- pip freeze"
pip freeze--- pip list
Package Version
------------------ ----------
certifi 2026.10.23
charset-normalizer 3.5.2
idna 3.20
markdown-it-py 4.2.0
mdurl 0.1.2
pip 26.2.2
Pygments 2.21.0
requests 2.31.0
rich 13.9.4
urllib3 2.8.0
--- only what nobody depends on (what you asked for)
Package Version
-------- -------
pip 26.2.2
requests 2.31.0
rich 13.9.4
--- newer versions on the index
Package Version Latest Type
-------- ------- ------ -----
requests 2.31.0 2.34.2 wheel
rich 13.9.4 15.0.0 wheel
--- pip freeze
certifi==2026.10.23
charset-normalizer==3.5.2
idna==3.20
markdown-it-py==4.2.0
mdurl==0.1.2
Pygments==2.21.0
requests==2.31.0
rich==13.9.4
urllib3==2.8.0
Notice what pip freeze loses: it prints nine flat lines and no longer knows that you asked for two packages and the other seven came along as dependencies. Commit that file and in a year nobody remembers whether Pygments is needed directly. (pip freeze also leaves out pip itself; pip list doesn't.) pip list --not-required recovers the top level, but only heuristically: a package you need directly and that something else depends on disappears from it.
This is the main reason the ecosystem moved to tools that keep two files: the dependencies you asked for (pyproject.toml) and the full resolution (a lockfile). You'll see that with pip-tools, Poetry and uv.
show: why is this here?
Requires lists a package's dependencies, and Required-by the installed packages that depend on it. Follow Required-by upwards to find out why something was installed:
python3 -m venv .venv && . .venv/bin/activate
pip install -q requests==2.31.0 rich==13.9.4
pip show urllib3 | grep -E '^(Name|Version|Requires|Required-by|Location)'
echo "---"
pip show -f rich | sed -n '/^Files:/,$p' | head -6Name: urllib3
Version: 2.8.0
Location: /home/learner/.venv/lib/python3.13/site-packages
Requires:
Required-by: requests
---
Files:
rich-13.9.4.dist-info/INSTALLER
rich-13.9.4.dist-info/LICENSE
rich-13.9.4.dist-info/METADATA
rich-13.9.4.dist-info/RECORD
rich-13.9.4.dist-info/REQUESTED
check: is the environment consistent?
pip's resolver keeps an environment consistent during an install, but you can still break it: installing with --no-deps, uninstalling a dependency by hand, or installing in two separate commands that disagree. pip check audits the result:
python3 -m venv .venv && . .venv/bin/activate
pip install -q --no-deps requests==2.31.0
pip check
echo "exit code: $?"
pip install -q requests==2.31.0
pip check
echo "--- uninstalling leaves dependencies behind"
pip uninstall -y -q requests
pip list --not-requiredrequests 2.31.0 requires certifi, which is not installed.
requests 2.31.0 requires charset-normalizer, which is not installed.
requests 2.31.0 requires idna, which is not installed.
requests 2.31.0 requires urllib3, which is not installed.
exit code: 1
No broken requirements found.
--- uninstalling leaves dependencies behind
Package Version
------------------ ----------
certifi 2026.10.23
charset-normalizer 3.5.2
idna 3.20
pip 26.2.2
urllib3 2.8.0
The last list shows a classic pip gotcha: pip uninstall requests removes only requests. Its four dependencies stay behind as orphans that nothing requires. Poetry and uv remove orphans automatically because they always sync the environment to a lockfile.
A runnable model: who requires whom
Required-by is computed, not stored: pip reads every installed package's Requires-Dist and inverts the graph. This model does the same and then finds the orphans left after an uninstall:
installed = {
"requests": ["charset-normalizer", "idna", "urllib3", "certifi"],
"rich": ["markdown-it-py", "pygments"],
"markdown-it-py": ["mdurl"],
"charset-normalizer": [], "idna": [], "urllib3": [], "certifi": [],
"pygments": [], "mdurl": [],
}
wanted = {"requests", "rich"} # what the user asked for
def required_by(pkg):
return sorted(name for name, deps in installed.items() if pkg in deps)
def reachable(roots):
seen, stack = set(), list(roots)
while stack:
p = stack.pop()
if p not in seen:
seen.add(p)
stack.extend(installed[p])
return seen
print("urllib3 is required by", required_by("urllib3"))
print("mdurl is required by", required_by("mdurl"))
del installed["requests"]; wanted.discard("requests") # pip uninstall requests
orphans = sorted(set(installed) - reachable(wanted))
print("orphans:", orphans)urllib3 is required by ['requests']
mdurl is required by ['markdown-it-py']
orphans: ['certifi', 'charset-normalizer', 'idna', 'urllib3']
Keeping the "wanted" set separate from the installed set is the whole trick, and it's exactly the information pip freeze throws away.
Test yourself
What information does pip freeze > requirements.txt lose?
- Version numbers
- Which packages you asked for versus which came in as dependencies
- Package names
- The Python version
How do you find out why urllib3 is installed?
- pip list --outdated
- pip show urllib3 and read Required-by
- pip check
- pip freeze | grep urllib3
After pip uninstall requests, what happens to urllib3?
- It is removed too
- It stays installed as an orphan
- pip refuses to uninstall
- It is downgraded