/commands/pip/pip-freeze-requirements-txt
pip freeze > requirements.txt: save installed packages to a requirements file
- tool
- pip
- versions
- pip 20+
- os
- any
pip freeze > requirements.txt writes every package installed in the current environment, one name==version line each, into requirements.txt. Anyone can then recreate the same set with pip install -r requirements.txt. Run it inside the project's virtual environment; outside one, it captures every package of your system or user Python.
Freeze an environment
uv run -q --no-project --python 3.13 --with pip==25.2 --with six==1.16.0 --with idna==3.10 \
python -m pip freeze --disable-pip-version-check > requirements.txt
cat requirements.txtOutput
idna==3.10 six==1.16.0
The example builds a throwaway environment with uv that contains pip, six and idna, then runs pip freeze in it; in your own activated venv the command is simply pip freeze > requirements.txt. pip itself is not listed: freeze hides pip, setuptools, wheel and distribute unless you pass --all.
Options
| Command | What it does |
|---|---|
| pip freeze > requirements.txt | Save every installed package with its exact version |
| pip freeze --all | Also list pip, setuptools and wheel |
| pip freeze --exclude-editable | Leave out packages installed with pip install -e |
| pip freeze -l (--local) | In a venv with access to global packages, list only the venv ones |
| pip freeze --user | Only packages installed in the user site (pip install --user) |
| pip freeze -r requirements.in | Keep the order and comments of an existing file, then list the extra packages |
| pip list --format=freeze | The same format from pip list |
| python -m pip freeze | Use the pip of a specific interpreter, for example py -3.12 -m pip freeze |
Pitfalls
- Everything is pinned, including transitive dependencies. That is what makes the file reproducible, but it also means you edit versions of packages you never chose. Many projects keep the direct dependencies in
requirements.in(orpyproject.toml) and generate the pinned file withpip-compileoruv pip compile. @ file://lines. Packages installed from a local folder or a wheel on disk are written asname @ file:///path/..., which does not work on another machine. Install them from an index or a Git URL instead.- Platform-specific packages. A file frozen on Windows can contain packages such as
pywin32that do not install on Linux. Add environment markers (pywin32==306; sys_platform == "win32") by hand. - Wrong environment. If the list is huge, you probably froze the global Python. Check
python -c "import sys; print(sys.prefix)"and activate the venv first, see create a virtual environment. - Wrong file name or path on install gives Could not open requirements file, and a malformed line gives Invalid requirement.
How to confirm it worked
cat requirements.txt shows one name==version line per package. To check the file installs cleanly, create a new venv and run pip install -r requirements.txt there, then pip freeze again and compare the two outputs with diff.
FAQ
Why does pip freeze list packages I never installed?
It lists everything in the environment, including dependencies of the packages you installed and, outside a virtual environment, every package of the system or user Python. Run it inside a project venv to get only that project's packages.
How do I recreate the environment from requirements.txt?
Create and activate a fresh virtual environment, then run pip install -r requirements.txt. Because freeze writes exact == versions, you get the same versions as on the machine that wrote the file.
What is the difference between pip freeze and pip list?
pip list is for people: a table with names and versions, and it includes pip itself. pip freeze prints name==version lines in the requirements format and hides pip, setuptools and wheel unless you add --all.