Skip to the workspace
Pebellslearn by building
Setting Up: Virtual Environments and Installing Django  ›  Capstone Project

Pinning Your Dependencies

Installing Django 10 minA requirements file records the exact packages a project needs, so anyone can recreate the same environment with a single pip command.

django / Pinning Your Dependencies

Explore each scene at your own pace.

01 · The rule

The rule

Pinning Your Dependencies

The cookbook runs on your laptop. A teammate clones it, installs "Django", gets a newer release than yours, and a page that works for you crashes for them. The code was identical; the packages were not. The cure is a plain text file that says exactly what the project runs on.

The rule

Share the list, not the folder: requirements.txt rebuilds any environment.

A requirements file lists one package per line, usually with an exact version (== is called pinning):

asgiref==3.9.1
Django==5.2.6
sqlparse==0.5.3

You can write it by hand, or capture what is installed in the active environment:

pip freeze > requirements.txt

pip freeze prints every package in the environment with its exact version, including the dependencies Django pulled in. That is why a clean environment matters: freeze a messy one and the list fills with packages the project never uses.

On any other machine, rebuild it:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

The -r flag means "read the requirements from this file". Commit requirements.txt to the repository; keep .venv/ in .gitignore.

Exact pins give repeatable installs. When you want to upgrade, do it on purpose: install the newer version, run the tests, then freeze again and commit the new list.

(Tools like Poetry and uv keep the same idea in a lock file. The file name changes; the principle does not.)

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.