To start working with Django, you first need to install Python and Django. This guide walks you through setting up Python, pip, Django, and virtual environments for a smooth Django development experience.
# Python installation on Ubuntu Linux
sudo apt-get update
sudo apt-get install python3
# Check installed Python version
python3 --version
If you're using Windows or macOS, download the latest Python version from the official Python website.
# Install pip for Python 3
sudo apt-get install python3-pip
# Verify pip installation
pip3 --version
pip is the tool used to install Python packages, including Django. Make sure it is installed correctly.
# Install Django using pip
pip3 install django
# Verify Django installation
django-admin --version
This installs the latest version of Django globally. You can also install specific versions if required.
It is a best practice to install Django inside a virtual environment to avoid dependency conflicts.
# Install virtualenv package
pip3 install virtualenv
# Create virtual environment
python3 -m venv myenv
# Activate virtual environment
source myenv/bin/activate
# Install Django inside virtual environment
pip install django
# Verify Django version
django-admin --version
Below is a simple command flow showing how Django setup typically looks:
# Typical Django project creation flow
django-admin startproject myproject
cd myproject
python manage.py runserver
Click a command to see the result:
django-admin startproject and start the server