In this lesson, you will learn how to install Django using Python's package manager, pip. You will also learn how to verify the installation and understand some common Django installation commands.
Installing Django means adding the Django Python package to your Python environment so that you can create and run Django web applications.
Django is installed using Python's package management tools.
Before installing Django, you should have:
First, check whether Python is installed.
python --version
If your system uses python3, you can use:
python3 --version
pip is used to install Python packages. Check it with:
pip --version
You can also use:
python -m pip --version
It is useful to create a separate folder for your Django project.
For example:
mkdir MyDjangoProject
cd MyDjangoProject
You can choose any suitable project folder name.
Create a virtual environment inside the project directory:
python -m venv venv
This creates an isolated Python environment named venv.
On Windows Command Prompt, activate the virtual environment with:
venv\Scripts\activate
You should normally see (venv) in the terminal prompt after activation.
On Linux or macOS, use:
source venv/bin/activate
The virtual environment is now active.
The standard way to install Django is through pip.
python -m pip install Django
pip downloads Django and installs it into the active Python environment.
You can also install Django using the direct pip command:
pip install Django
Using python -m pip can make it clearer which Python
installation is being used.
After running the installation command, pip downloads Django and its required dependencies.
The process may take some time depending on your internet connection and Python environment.
After installation, verify Django using:
python -m django --version
If Django is installed correctly, its version number will be displayed.
Django also provides a command-line utility called
django-admin.
Check its version with:
django-admin --version
django-admin is used for several Django command-line tasks,
including creating a new Django project.
Later, you will use it to create your first Django project.
You can display information about the installed Django package using:
python -m pip show Django
This can show the installed version, location and other package information.
To see the packages installed in the active environment, use:
python -m pip list
Django should appear in the list after successful installation.
Sometimes a project requires a specific Django version.
For example:
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
Before upgrading an existing project, check that the project is compatible with the target Django version.
If you need to remove Django from the active environment, use:
python -m pip uninstall Django
pip will ask for confirmation before removing the package.
You can update pip before installing Django:
python -m pip install --upgrade pip
Keeping package-management tools updated can help avoid some installation issues.
If you are using a virtual environment, activate it before installing Django.
venv\Scripts\activate
python -m pip install Django
This ensures the package is installed in the intended environment.
Django projects often use a requirements.txt file to record
their Python dependencies.
After installing Django, you can create such a file using:
python -m pip freeze > requirements.txt
If a project already contains a requirements.txt file,
install its dependencies using:
python -m pip install -r requirements.txt
This is useful when setting up an existing Django project.
If the terminal says that python or pip is not
recognized, Python may not be correctly installed or available through
the system PATH.
Check the Python installation and try the appropriate command for your system.
If you see an error indicating that the Django module cannot be found, check whether the correct virtual environment is active.
Then run:
python -m django --version
A simple workflow is:
mkdir MyDjangoProject
cd MyDjangoProject
python -m venv venv
venv\Scripts\activate
python -m pip install Django
python -m django --version
This sequence prepares a project directory, creates an isolated environment, installs Django and verifies the installation.
mkdir MyDjangoProject
cd MyDjangoProject
python3 -m venv venv
source venv/bin/activate
python -m pip install Django
python -m django --version
This follows the same basic process with the platform-specific Python and activation commands.
Once Django is installed and its version can be displayed, the environment is ready for creating a Django project.
In the next lessons, you will learn more about Django commands and how to create your first project.
Django can be installed using Python's pip package manager. A typical installation inside a virtual environment is:
python -m venv venv
venv\Scripts\activate
python -m pip install Django
python -m django --version
After successful installation, Django is ready for project development.
python -m pip install Django to install Django.python -m django --version to verify Django.django-admin is Django's command-line utility.requirements.txt can be used to record dependencies.Question: Which command is commonly used to install Django using pip?