Full Byte Developer.

pip freeze shows your laptop, not your repo

Pin what you install, not what pip freeze finds.

Published here · 3 sources

bash
pip freeze > requirements.txt

Do this in a shared, polluted environment and the file lists packages your project never uses.

Why

pip freeze outputs every package installed in the current Python environment. If that environment also has another project's dependencies, dev tools like black or ipython, or leftovers from past experiments, they go in too.

A cleaner path

Keep a pyproject.toml that lists your direct dependencies under [project] dependencies. Install with pip install .. pip freeze still lists subs, but they are all real sub-dependencies.

After shipping a bloated file

Compare with pipdeptree (requires install):

bash
pipdeptree --warn silence

Remove packages that are not subs of your imports.

Send this to the teammate whose requirements.txt lists every package on their laptop.

Keep this guide

By Full Byte Developer

Filed under Dev tools

Questions about this guide

Why does pip freeze add packages I did not install?

It outputs every package installed in the current Python environment, including sub-dependencies, tools and leftovers from other projects.

How do I export only my direct installs?

With pipdeptree --user-only, or by keeping a pyproject.toml with dependencies = [...] and running pip install .

Sources

  1. pip docs: freezepip.pypa.io
  2. pipdeptreepypi.org

Next in this stack