requirements.txt
In Python, a requirements.txt file lists the packages that a project needs, usually one per line, so that a single command can install all of them. Each line names a distribution and can pin an exact version, such as requests==2.34.2.
A requirements file describes a concrete environment rather than a project’s own metadata. pip reads a project’s declared dependencies from pyproject.toml or setup.py, not from a requirements.txt sitting next to them.
That split is why requirements files show up wherever repeatability matters. Pinning exact versions lets you lock an application deployment, a CI job, or a tutorial’s sample code to a set of releases you’ve already tested together.
Lines aren’t limited to plain requirement specifiers. A line can point at an archive URL, a local path, or a version-control checkout, and it can carry an environment marker so that a package installs only on certain Python versions or platforms. Lines starting with # are comments, -r includes another requirements file, and -e installs a project in editable mode.
Example
Say you’re deploying a small web app and want your teammates to run the same versions you tested against. Pin those versions in a requirements file:
requirements.txt
# Web app dependencies
flask==3.1.3
requests==2.34.2
Now anyone can rebuild that setup from the file inside a fresh virtual environment:
$ python -m venv venv/
$ source venv/bin/activate
(venv) $ python -m pip install -r requirements.txt
pip installs both pinned packages along with their transitive dependencies. Going the other way, python -m pip freeze > requirements.txt writes the packages currently installed in the environment back out to the file, each pinned to its exact version.
Run that round trip below to see how much longer the file gets once pip freeze writes it back:
Related Resources
Tutorial
Using Python's pip to Manage Your Projects' Dependencies
What is pip? In this beginner-friendly tutorial, you'll learn how to use pip, the standard package manager for Python, so that you can install and manage packages that aren't part of the Python standard library.
For additional information on related topics, take a look at the following resources:
- Python Virtual Environments: A Primer (Tutorial)
- uv vs pip: Managing Python Packages and Dependencies (Tutorial)
- A Beginner's Guide to pip (Course)
- Working With Python Virtual Environments (Course)
- Python Basics: Installing Packages With pip (Course)
- Using Python's pip to Manage Your Projects' Dependencies (Quiz)
- Python Virtual Environments: A Primer (Quiz)
- uv vs pip: Python Packaging and Dependency Management (Course)
- uv vs pip: Managing Python Packages and Dependencies (Quiz)
By Martin Breuss • Updated Aug. 26, 2026