Isolated Environments and Packages · practice
Write Down What the Project Needs
The environment works now, but the project has not written down why. If .venv disappears, its package
A package your project needs in order to run is called a dependency: your code depends on it being there. Your project has exactly one so far, requests, at the exact version this chapter uses. Write that promise into a plain text file:
nano requirements.txt
cat requirements.txt
In nano, type requests==2.34.2, save with Ctrl + O, and leave with Ctrl + X. cat then prints the saved file.
You should see one line:
requests==2.34.2
The filename requirements.txt is a convention understood by pip and by people who work with Python projects. Each non-comment line is a requirement. This one states both the package and the exact version.
Direct is different from supporting
When pip installed requests, it also installed packages such as certifi, charset-normalizer, idna, and urllib3. Those are transitive dependencies: packages your direct dependency needs in order to do its job.
Do not copy that entire installed shelf into this exercise. The project made one choice, requests==2.34.2. pip can read that package’s own metadata and choose the verified supporting versions from the configured
There are projects that lock every transitive artifact for deployment. Python Land’s mirror itself does exactly that for reproducibility and supply-chain review. That platform lock solves a different problem from this beginner-sized project’s requirements file.
Why this file survives and .venv does not
requirements.txt is small, portable text written by you. It belongs to the project and is saved with the chapter. .venv is large, machine-specific output written by tools, so Python Land deliberately excludes it from the saved session snapshot and from downloads.
The rule is simple: keep the recipe; rebuild the result.
Your turn
Open requirements.txt with nano and add exactly this direct requirement:
requests==2.34.2
Comments and blank lines are fine. Do not add requests’ supporting packages, pytest, or uv. They are stocked by the site, but this project has not chosen them as runtime dependencies.
Run cat requirements.txt to inspect the durable file, then press Check my work. The check reads the resulting file. It cannot and does not prove which shell command you used.
Why does requirements.txt list only requests and not certifi, idna, and urllib3?