pip freeze shows your laptop, not your repo
Pin what you install, not what pip freeze finds.
Published here · 3 sources · Resume reading
pip freeze > requirements.txtDo 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):
pipdeptree --warn silenceRemove 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
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
- pip docs: freezepip.pypa.io
- pipdeptreepypi.org
- pip docs: requirements file formatpip.pypa.io