Django Installation, Virtualenv & Development Workspace Setup

Before authoring any Django application, establishing a clean, reproducible, and isolated local development environment is critical. This guide walks you through verifying your Python runtime, creating isolated virtual environments, and installing the latest LTS release of Django.

Step 1: Verify Python 3 Installation

Django 5.x requires Python 3.10, 3.11, or 3.12+. Open your terminal (PowerShell on Windows, Terminal on macOS/Linux) and execute:

# Check Python runtime version
python --version
# Output should be: Python 3.10.x, 3.11.x, or 3.12.x

# Check pip package manager version
python -m pip --version

Windows Path Warning

If Windows reports 'python' is not recognized as an internal or external command, re-run the Python installer from python.org and check the box that says "Add python.exe to PATH".

Step 2: Create and Activate an Isolated Virtual Environment

Navigate to your project folder and initialize an isolated virtual environment using Python's standard venv module:

# Navigate to your workspace directory
cd G:\Programming\django_workspace

# Create a virtual environment named 'venv'
python -m venv venv

# Activation on Windows PowerShell:
venv\Scripts\Activate.ps1

# Activation on Windows Command Prompt (CMD):
venv\Scripts\activate.bat

# Activation on macOS / Linux:
source venv/bin/activate

Once activated, your terminal prompt will display (venv) at the beginning of the command line, confirming that all subsequent pip install commands will be contained safely within this directory.

Step 3: Upgrade pip and Install Django

With the virtual environment active, ensure pip is updated and install Django:

# Upgrade pip to latest release
python -m pip install --upgrade pip

# Install the latest stable Django release
pip install django

# Verify the installation and version
python -m django --version
# Output example: 5.1.x

Step 4: Pinning Dependencies (requirements.txt)

In professional engineering and university lab submissions, always export your installed packages so team members and grading examiners can replicate your environment with a single command:

# Export installed dependencies
pip freeze > requirements.txt

# To install dependencies on another machine:
pip install -r requirements.txt

Quick Verification Lab

Open a Python interactive shell by typing python in your activated terminal. Type import django; print(django.get_version()). If it prints your version without an ImportError, your environment is ready to build projects!

Frequently Asked Questions (FAQ) - Student & Interview Review

Q1. Why should I always install Django inside a Python virtual environment?

A virtual environment creates an isolated sandbox for your Python packages. It prevents dependency conflicts between projects (e.g. Project A requiring Django 4.2 and Project B requiring Django 5.1) and ensures you never pollute your operating system's global Python installation.

Q2. What is the command to create and activate a virtual environment on Windows?

On Windows PowerShell or Command Prompt, run: `python -m venv myenv` to create it, followed by `myenv\Scripts\activate` to activate it.

Q3. How do I verify which version of Django is installed?

Run `python -m django --version` in your activated terminal, or run `django-admin --version`.

Q4. Can I use pipenv or poetry instead of venv?

Yes. Tools like Poetry, Pipenv, and Conda are fully compatible with Django. However, Python's built-in `venv` module remains the zero-dependency, universal standard recommended for beginners and university curricula.

Explore Related Django Tutorials & Next Steps

Broaden your backend architecture, REST API design, and production engineering expertise:

Projects vs Apps: Structural Best Practices

Create your first project and understand the purpose of each generated file.

Settings.py & Environment Variables

Manage configuration securely using django-environ and decouple secrets.

Django Models & Field Types

Construct relational database tables using Python class declarations.

BCA/MCA University Viva Questions

Quick-fire academic exam questions on Django installation, CLI, and setup.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!