Chapter 1: First Look at Django
1.2 Django Environment Setup
Python Environment Requirements
Django 5.x has specific requirements for Python version. Recommended version: Python 3.12+, better performance and supports latest features. Current highest version is Python 3.12.10 (released April 18, 2025).
Check Python Version
# Check Python version
python --version
# or
python -V
# Output example
Python 3.12.10If your system Python version is too old, use these methods to install new version:
Windows users:
- Visit windows version download to download latest version
- Or use Chocolatey:
choco install python
macOS users:
- Use Homebrew:
brew install python@3.12 - Or download installer from official website
Linux users:
# Ubuntu/Debian
sudo apt update
sudo apt install python3.12 python3.12-venv python3.12-pip
# CentOS/RHEL
sudo dnf install python3.12 python3.12-venv python3.12-pipVirtual Environment Creation
Virtual environment creates separate Python environment for each project, avoids dependency conflicts.
Create Virtual Environment with venv
# Create virtual environment
python -m venv django_env
# Windows activation
django_env\Scripts\activate
# macOS/Linux activation
source django_env/bin/activate
# After activation, command prompt shows virtual environment name
(django_env) $Virtual Environment Management
# View installed packages
pip list
# Upgrade pip to latest version
python -m pip install --upgrade pip
# Exit virtual environment
deactivate
# Delete virtual environment (delete folder directly)
rm -rf django_env # Linux/macOS
rmdir /s django_env # WindowsUse conda (Optional)
If you use Anaconda or Miniconda:
# Create conda environment
conda create -n django_env python=3.12
# Activate environment
conda activate django_env
# Exit environment
conda deactivateDjango 5.x Installation
Make sure virtual environment is activated, then install Django.
Install Latest Version
# Install latest Django version
pip install django
# Install specific version
pip install django=<version number>
# Verify installation
python -m django --version
# Output example: 5.0.1Install Additional Dependencies
Depending on project needs, may need to install extra packages. Or install when needed. Better to accumulate some commonly used packages for batch installation based on your usage habits.
# Database drivers
pip install psycopg2-binary # PostgreSQL
pip install mysqlclient # MySQL
pip install cx_Oracle # Oracle
# Development tools
pip install django-debug-toolbar # Debug toolbar
pip install django-extensions # Django extensions
# Production environment
pip install gunicorn # WSGI server
pip install whitenoise # Static file serviceDevelopment Tool Recommendations
Code Editors/IDEs
Visual Studio Code
- Lightweight and powerful
- Rich plugin ecosystem
- Recommended plugins:
- Python
- Django
- Python Docstring Generator
- GitLens
AI IDE In China, main large models are Deepseek, Tongyi Qianwen, etc.
PyCharm Professional
- Most comprehensive Django IDE
- Built-in Django support
- Powerful debugging features
- Database integration
VSCode Django Development Configuration
Create .vscode/launch.json (debug configuration):
{
"version": "0.2.0",
"configurations": [
{
"name": "Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver"
],
"django": true,
"justMyCode": true
}
]
}Database Management Tools
Strongly recommend free client software, can manage MySQL, PostgreSQL, Sqlite databases. https://www.heidisql.com/
Project Dependency Management
requirements.txt
Create requirements.txt file to manage project dependencies:
# Generate dependency file
pip freeze > requirements.txt
# Install dependencies
pip install -r requirements.txtExample requirements.txt:
Django==5.0.1
psycopg2-binary==2.9.7
Pillow==10.0.1
django-debug-toolbar==4.2.0Development and Production Environment Separation
Create different dependency files:
requirements/base.txt:
Django==5.0.1
Pillow==10.0.1requirements/dev.txt:
-r base.txt
django-debug-toolbar==4.2.0
django-extensions==3.2.3
ipython==8.15.0requirements/prod.txt:
-r base.txt
gunicorn==21.2.0
whitenoise==6.5.0Installation methods:
# Development environment
pip install -r requirements/dev.txt
# Production environment
pip install -r requirements/prod.txtEnvironment Verification
After entering virtual environment, verify installation:
python -V
> Python 3.12.10
python -m django --version
> 5.2.6Common Problem Solutions
1. pip installation slow
# Use domestic mirror source
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple django
# Or configure permanent mirror source
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple2. Permission errors
# macOS/Linux use user installation
pip install --user django
# Or use sudo (not recommended)
sudo pip install djangoSummary
Now you have successfully set up Django development environment:
- ✅ Installed Python 3.12+
- ✅ Created virtual environment
- ✅ Installed Django 5.x
- ✅ Configured development tools
- ✅ Set up dependency management
Next Article
We will create first Django project, start actual Django development journey!
1.3 First Django Project →