A requirements freeze file captures the exact package versions from a working Python environment so the same dependency set can be rebuilt later. That snapshot is useful before handing a project to another machine, recreating a virtual environment, or preserving a known-good package state ahead of upgrades.
The python -m pip freeze command reads the installed distributions for one specific interpreter and emits them in pip requirements format. Running the command through the interpreter instead of a standalone pip executable keeps the export tied to the intended virtual environment or Python installation instead of whichever pip command appears first in PATH.
The main risk is capturing the wrong environment. pip freeze reports what is already installed and does not generate a solver-based lockfile, and current pip documentation notes that bootstrap packaging tools are omitted by default unless –all is used. On Python 3.12 and later, only pip is skipped by default; on Python 3.11 and earlier, setuptools, wheel, and distribute are also omitted when present.
$ source .venv/bin/activate (.venv) $ python -m pip --version pip 26.0.1 from /srv/apps/acme-api/.venv/lib/python3.14/site-packages/pip (python 3.14)
The path after from should point at the intended virtual environment or interpreter prefix before writing the freeze file.
Substitute python3 or py when that is the normal interpreter command in the selected environment.
(.venv) $ python -m pip freeze > requirements.txt
requirements.txt is the conventional filename, but any writable path works when the same file is later referenced with -r.
(.venv) $ sed -n '1,10p' requirements.txt certifi==2026.2.25 charset-normalizer==3.4.6 idna==3.11 requests==2.33.0 urllib3==2.6.3
pip freeze output is sorted case-insensitively in requirements format. Packages installed from a local path, archive, or VCS source can appear as direct references instead of simple name==version pins.
(.venv) $ python -m pip freeze --all > requirements.txt (.venv) $ sed -n '1,10p' requirements.txt certifi==2026.2.25 charset-normalizer==3.4.6 idna==3.11 pip==26.0.1 requests==2.33.0 urllib3==2.6.3
Current virtual environments on modern Python releases may include only pip as a bootstrap package, so –all shows additional tools only when they are actually installed.
(.venv-rebuild) $ python -m pip install -r requirements.txt Collecting certifi==2026.2.25 (from -r requirements.txt (line 1)) Collecting charset-normalizer==3.4.6 (from -r requirements.txt (line 2)) Collecting idna==3.11 (from -r requirements.txt (line 3)) Collecting requests==2.33.0 (from -r requirements.txt (line 4)) Collecting urllib3==2.6.3 (from -r requirements.txt (line 5)) Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests Successfully installed certifi-2026.2.25 charset-normalizer-3.4.6 idna-3.11 requests-2.33.0 urllib3-2.6.3
Use the export only for the environment it represents. Cross-platform or cross-interpreter rebuilds can still fail when wheels, build requirements, or platform markers differ.