Lesson 7 of 60 – Install Django
12%

📦 Install Django

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.

Note: Before installing Django, make sure Python is installed and preferably activate a virtual environment for your project.

1. What Is Django Installation?

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.

2. Requirements Before Installing Django

Before installing Django, you should have:

  • Python installed
  • pip available
  • A terminal or command prompt
  • A suitable project directory

3. Check Python

First, check whether Python is installed.

python --version

If your system uses python3, you can use:

python3 --version

4. Check pip

pip is used to install Python packages. Check it with:

pip --version

You can also use:

python -m pip --version

5. Create a Project Folder

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.

6. Create a Virtual Environment

Create a virtual environment inside the project directory:

python -m venv venv

This creates an isolated Python environment named venv.

7. Activate the Environment on Windows

On Windows Command Prompt, activate the virtual environment with:

venv\Scripts\activate

You should normally see (venv) in the terminal prompt after activation.

8. Activate the Environment on Linux/macOS

On Linux or macOS, use:

source venv/bin/activate

The virtual environment is now active.

9. Install Django Using pip

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.

10. Install Django Using pip Command

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.

11. Wait for the Installation

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.

12. Verify Django Installation

After installation, verify Django using:

python -m django --version

If Django is installed correctly, its version number will be displayed.

13. Use django-admin

Django also provides a command-line utility called django-admin.

Check its version with:

django-admin --version

14. django-admin and Python

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.

15. Check Installed Django Package

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.

16. View All Installed Packages

To see the packages installed in the active environment, use:

python -m pip list

Django should appear in the list after successful installation.

17. Install a Specific Django Version

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.

18. Upgrade Django

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.

19. Uninstall Django

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.

20. Upgrade pip Before Installing

You can update pip before installing Django:

python -m pip install --upgrade pip

Keeping package-management tools updated can help avoid some installation issues.

21. Install Django in an Active Environment

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.

22. requirements.txt

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

23. Install Dependencies from 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.

24. Common Command Not Found Error

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.

25. Django Module Not Found

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

26. Basic Django Installation Workflow

A simple workflow is:

  1. Check Python
  2. Check pip
  3. Create a project folder
  4. Create a virtual environment
  5. Activate the environment
  6. Install Django
  7. Verify Django

27. Complete Windows Example

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.

28. Complete Linux/macOS Example

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.

29. Django Is Ready for Project Creation

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.

30. Django Installation Summary

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.

📌 Key Points

  • Django is installed as a Python package.
  • pip is commonly used to install Django.
  • A virtual environment is recommended for project dependencies.
  • Use python -m pip install Django to install Django.
  • Use python -m django --version to verify Django.
  • django-admin is Django's command-line utility.
  • requirements.txt can be used to record dependencies.

🧠 Quick Quiz

Question: Which command is commonly used to install Django using pip?