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.xA few details in there matter:
python -m pipruns the pip that belongs to the active Python, which removes any doubt about which pip you got.- The version range
>=5.2,<5.3means "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 listDjango 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.
Confirm Python
python --versionshows 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.
Which command prints the installed Django version?
What does "Django>=5.2,<5.3" allow pip to install?
Why wrap the requirement in quotes on the command line?
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.
