Lesson 5 of 60 – Django Installation
8%

⚙️ Django Installation

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.

Note: Before installing Django, make sure Python and the Python package manager pip are available on your system.

1. Check Python Installation

First, check whether Python is already installed on your computer.

python --version

You should see a Python version such as:

Python 3.x.x

2. Python 3 Is Required

Modern Django development uses Python 3. Make sure you are using a supported Python 3 version.

Check the installed version before starting Django development.

3. Check Python Using python3

On some Linux and macOS systems, Python is accessed using python3.

python3 --version

This command displays the installed Python 3 version.

4. What Is pip?

pip is the package installer commonly used with Python. It allows you to install Python packages such as Django.

pip --version

5. Check pip Installation

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.

6. Open Command Prompt on Windows

Windows users can open Command Prompt or PowerShell.

Then type:

python --version

7. Open Terminal on Linux or macOS

Linux and macOS users can open the Terminal application.

Then check Python using:

python3 --version

8. Upgrade pip

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

9. Install Django with 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.

10. Install Django Using pip3

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.

11. Verify Django Installation

After installation, check the Django version.

django-admin --version

If Django was installed successfully, the command displays its version number.

12. Check Django Through Python

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.

13. What Is django-admin?

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.

14. Create a Virtual Environment

A virtual environment keeps project dependencies separate from other Python projects.

We can create one using:

python -m venv venv

15. Activate Virtual Environment on Windows

On Windows Command Prompt, activate the environment using:

venv\Scripts\activate

After activation, the environment name may appear in the command prompt.

16. Activate Virtual Environment on Linux/macOS

On Linux or macOS, the activation command is:

source venv/bin/activate

After activation, packages installed with pip are installed into the virtual environment.

17. Install Django Inside 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.

18. Why Use a Virtual Environment?

Different projects may require different package versions. A virtual environment helps keep those dependencies separate.

  • Project isolation
  • Separate dependencies
  • Cleaner development environment
  • Better project management

19. Check the Active Environment

After activation, your terminal generally shows the virtual environment name before the command prompt.

For example:

(venv) C:\DjangoProject>

20. Install a Specific Django Version

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.

21. Upgrade Django

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.

22. View Installed Packages

You can see installed Python packages using pip.

python -m pip list

The command displays packages installed in the active Python environment.

23. Show Django Package Information

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.

24. Common Installation Error

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.

25. Another Common Error

If Django cannot be found after installation, first check whether the correct virtual environment is activated.

python -m django --version

26. Recommended Installation Workflow

A basic Django setup can follow these steps:

  1. Install Python
  2. Check Python
  3. Create a virtual environment
  4. Activate the environment
  5. Install Django
  6. Check the Django version

27. Basic Windows Example

Example workflow on Windows:

python --version
python -m venv venv
venv\Scripts\activate
python -m pip install Django
python -m django --version

28. Basic Linux/macOS Example

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

29. Django Is Now Ready

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.

30. Installation Summary

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

📌 Key Points

  • Django is a Python web framework.
  • Python should be installed before Django.
  • pip is commonly used to install Django.
  • A virtual environment helps isolate project dependencies.
  • Django can be installed using python -m pip install Django.
  • Use python -m django --version to verify Django.
  • django-admin provides Django command-line functionality.

🧠 Quick Quiz

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