In this lesson, you will learn how to install Django on your computer. Django is a Python web framework, so Python should be installed before installing Django.
First, check whether Python is already installed on your computer.
python --version
You should see a Python version such as:
Python 3.x.x
Modern Django development uses Python 3. Make sure you are using a supported Python 3 version.
Check the installed version before starting Django development.
On some Linux and macOS systems, Python is accessed using
python3.
python3 --version
This command displays the installed Python 3 version.
pip is the package installer commonly used with Python. It allows you to install Python packages such as Django.
pip --version
Run the following command to check whether pip is available:
pip --version
If pip is installed correctly, the command displays its version and installation location.
Windows users can open Command Prompt or PowerShell.
Then type:
python --version
Linux and macOS users can open the Terminal application.
Then check Python using:
python3 --version
It is often useful to update pip before installing Python packages.
python -m pip install --upgrade pip
On systems where Python is accessed as python3, you can use:
python3 -m pip install --upgrade pip
The simplest way to install Django is through pip.
python -m pip install Django
pip downloads Django and installs it into the current Python environment.
On some systems, you may use pip3 instead.
pip3 install Django
The exact command depends on how Python and pip are configured on your system.
After installation, check the Django version.
django-admin --version
If Django was installed successfully, the command displays its version number.
You can also check the Django version using Python.
python -m django --version
This is another useful way to verify that Django is available to Python.
django-admin is a command-line utility provided by Django.
It can be used for tasks such as creating Django projects and inspecting Django information.
A virtual environment keeps project dependencies separate from other Python projects.
We can create one using:
python -m venv venv
On Windows Command Prompt, activate the environment using:
venv\Scripts\activate
After activation, the environment name may appear in the command prompt.
On Linux or macOS, the activation command is:
source venv/bin/activate
After activation, packages installed with pip are installed into the virtual environment.
Once the virtual environment is activated, install Django:
python -m pip install Django
This keeps the Django installation associated with that project environment.
Different projects may require different package versions. A virtual environment helps keep those dependencies separate.
After activation, your terminal generally shows the virtual environment name before the command prompt.
For example:
(venv) C:\DjangoProject>
pip can install a particular Django version when a project requires it.
python -m pip install Django==5.2
The version number can be changed according to the project's requirements.
If Django is already installed and you want to upgrade it, use:
python -m pip install --upgrade Django
Always consider project compatibility before upgrading a production project.
You can see installed Python packages using pip.
python -m pip list
The command displays packages installed in the active Python environment.
The following command provides information about the installed Django package:
python -m pip show Django
It can show information such as the installed version and package location.
If the terminal says that python or pip is not
recognized, Python may not be installed correctly or may not be available
through the system PATH.
Check the Python installation and try the appropriate Python command again.
If Django cannot be found after installation, first check whether the correct virtual environment is activated.
python -m django --version
A basic Django setup can follow these steps:
Example workflow on Windows:
python --version
python -m venv venv
venv\Scripts\activate
python -m pip install Django
python -m django --version
Example workflow on Linux or macOS:
python3 --version
python3 -m venv venv
source venv/bin/activate
python -m pip install Django
python -m django --version
Once the installation is successful and the Django version can be displayed, your environment is ready for the next steps.
In the next lessons, we will learn more about virtual environments, Django projects, and Django commands.
Django installation mainly involves preparing Python, optionally creating a virtual environment, installing Django with pip, and verifying the installation.
python -m pip install Django
After installation, verify it with:
python -m django --version
python -m pip install Django.python -m django --version to verify Django.django-admin provides Django command-line functionality.Question: Which command is commonly used to install Django with pip?