How to install Django? Install Django in a Virtual Environment
This tutorial will guide you through the process of installing Django. Starting with the process of installation of Python and PIP. Create a virtual environment and then activate it, So we are ready to install Django.
Install Django
1. Install Python and PIP
Django is a Python web framework, so you need to have Python installed on your system. You can check if Python is already installed by running the following command in your terminal or command prompt:
python --version
pip --version
If Python is not installed, you can download and install it from the official Python website (https://www.python.org).
2. Create a virtual environment and activate it
Learn to create a virtual environment in python and activating the environment to install the specific dependencies or packages in it. This allows you to install specific packages for each project without interfering with the system-wide Python installation.
3. Install Django
Note: Always install Django while you are in the virtual environment!
After you’ve created and activated a virtual environment, type the command in terminal:
For Unix / Mac OS:
python -m pip install Django
For Windows:
py -m pip install Django
(myenv) C:\Users\Your Name>python -m pip install Django
Here, myenv is a virtual environment that we created and you should look for when it's activated.
Output that looks like this (I am using my Windows Subsystem for Linux machine (WSL) Ubuntu 22.04):
(myenv) root@upworth:/mnt/c/Users/kalyan/django_projects# python -m pip install django
Collecting django
Downloading Django-4.2.3-py3-none-any.whl (8.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.0/8.0 MB 9.8 MB/s eta 0:00:00
Collecting sqlparse>=0.3.1
Using cached sqlparse-0.4.4-py3-none-any.whl (41 kB)
Collecting asgiref<4,>=3.6.0
Using cached asgiref-3.7.2-py3-none-any.whl (24 kB)
Collecting typing-extensions>=4
Downloading typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Installing collected packages: typing-extensions, sqlparse, asgiref, django
Successfully installed asgiref-3.7.2 django-4.2.3 sqlparse-0.4.4 typing-extensions-4.7.1
Great! Now you have Django installed in your new project, running in a virtual environment!
4. Check Django Version
You can check if Django is installed, by typing this in terminal:
django-admin --version
If Django is installed, it will show the output:
4.2.3
You have successfully installed Django. Now you are ready to create a Django project and apps in a virtual environment on your system.