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.