Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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.)

The shortcut

Every time you pip install something new, finish the move with pip freeze > requirements.txt and commit. Install and freeze are one gesture.

Adding a package to the cookbookStep 1 of 4
  1. Install

    With (.venv) active, pip install pillow so recipes can have photos.

The trap is installing something, forgetting to freeze, and pushing code that imports a package the file never mentions. It works on your machine only.

Drills

Answer fast — trust the rule.

quick drill

Which command installs everything listed in requirements.txt?

quick drill

What does Django==5.2.6 in a requirements file mean?

quick drill

Why freeze from a clean, project-only environment?

quick drill

Which of these belongs in the Git repository?

Remember

  • Share the list, not the folder: requirements.txt rebuilds any environment.
  • Install and freeze are one gesture; commit the file with the code.
  • Trap: an import that is not in the file only works on your machine.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainRebuild it on a new laptop

A teammate clones the cookbook repository onto a new laptop. Explain what file you should have committed and the exact steps they run to end up with the same Django version you use.