Setting up Django Project with virtual Environment

I’ll walk you through Django + virtual environment on Linux and Windows, step-by-step, clean and beginner-safe.
1️⃣ Prerequisites (both Linux & Windows)
Make sure Python is installed:
python --version
or
python3 --version
If it prints Python 3.x.x, you’re good.
2️⃣ Create a Project Folder
mkdir django_project
cd django_project
This folder will hold:
virtual environment
Django project code
🪟 WINDOWS (CMD / PowerShell)
3️⃣ Create Virtual Environment
python -m venv env
4️⃣ Activate Virtual Environment
▶ CMD
env\Scripts\activate
▶ PowerShell
env\Scripts\Activate.ps1
If PowerShell blocks it, run once as admin:
Set-ExecutionPolicy RemoteSigned
Then activate again.
You’ll see:
(env) C:\django_project>
5️⃣ Upgrade pip
python -m pip install --upgrade pip
6️⃣ Install Django
pip install django
Check:
django-admin --version
7️⃣ Create Django Project
django-admin startproject mysite .
mysite . will create the project in current folder/directory as . represent current directorydjango-admin startproject mysite
cd mysite
8️⃣ Run Server
python manage.py runserver
Open browser 👉
👉 http://127.0.0.1:8000/
9️⃣ Deactivate Virtual Environment
deactivate
🐧 LINUX (Ubuntu, Debian, Arch, etc.)
Create Virtual Environment
python3 -m venv env
This creates a folder called env.
Activate Virtual Environment
source env/bin/activate
You’ll see something like:
(env) user@machine:~/django_project$
👉 This means virtual env is active
Upgrade pip (recommended)
pip install --upgrade pip
Install Django
pip install django
Verify:
django-admin --version
Create Django Project
django-admin startproject mysite
cd mysite
Folder structure:
django_project/
├── venv/
└── mysite/
├── manage.py
└── mysite/
Run Development Server
python manage.py runserver
Open browser 👉
👉 http://127.0.0.1:8000/
🎉 Django welcome page = SUCCESS
Deactivate Virtual Environment
deactivate
🔥 Common Mistakes (Important)
❌ Forgetting to activate venv
❌ Installing Django globally
❌ Running runserver outside project folder
❌ Using python vs python3 incorrectly on Linux
🧠 Pro Tip (Best Practice)
Managing Dependency using pip freeze
pip freeze will output the list of packages with versions installed in the current virtual environment (if activated)

We can then save that list to a file named requirements.txt for future ( so we can reinstall everything in new setup environment)
pip freeze > requirements.txt
This will make a file named requirements.txt and save the output of pip freeze that has packages and its versions
Later you can install everything with:
pip install -r requirements.txt
