Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Setting Up: Virtual Environments and Installing Django  ›  Lesson

Installing Django

Installing Django 10 minWith the environment active, pip installs Django from the Python Package Index, and a quick version check confirms which release the project will run.

Installing Django

The environment is ready and empty. Now Django itself goes in. It takes one command, but a few seconds of care here, choosing a version and checking where it landed, saves an afternoon of confusion later.

The rule

Activate, install, verify: three commands, always in that order.

Django is published on PyPI, the Python Package Index, and pip fetches it from there. Django 5.x needs Python 3.10 or newer, so check that first:

python --version                             # 3.10 or higher
source .venv/bin/activate                    # 1. activate
python -m pip install "Django>=5.2,<5.3"     # 2. install
python -m django --version                   # 3. verify: 5.2.x

A few details in there matter:

  • python -m pip runs the pip that belongs to the active Python, which removes any doubt about which pip you got.
  • The version range >=5.2,<5.3 means "any 5.2 bug-fix release, but not 5.3". Bug fixes come in; surprises do not. 5.2 is a long-term support release, which gets security fixes for years.
  • The quotes matter: without them the shell reads < and > as file redirects.

Installing Django also brings two small dependencies, asgiref and sqlparse. See everything in the environment with:

pip list

Django also puts a command-line tool on your path, django-admin, which you will use in a moment to create the project.

The shortcut

Treat verify as part of installing, not an optional extra. If python -m django --version prints a version, Django is importable from this Python. If it errors, the install went somewhere else, almost always because the environment was not active.

Django into the cookbook environmentStep 1 of 4
  1. Confirm Python

    python --version shows 3.12. Recent enough for Django 5.2.

A common slip: pip install django "succeeds", but python -m django says there is no module named django. Two different Pythons are involved; activate, then use python -m pip so both commands refer to the same one.

Drills

Answer fast — trust the rule.

quick drill

Which command prints the installed Django version?

quick drill

What does "Django>=5.2,<5.3" allow pip to install?

quick drill

Why wrap the requirement in quotes on the command line?

quick drill

Which Python version is too old for Django 5.x?

Remember

  • Activate, install, verify: always in that order.
  • Pin a range such as >=5.2,<5.3, and quote it on the command line.
  • Trap: a successful install that the project cannot import means two different Pythons.

Practice — level up

0/1 solved

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

ExplainInstall and prove it

Write the sequence of commands to install Django 5.2 for the cookbook and confirm it worked. Explain what each command does and how you would tell the install went into the right place.