DEV Community

Mehedi Alam
Mehedi Alam

Posted on AI-assisted

Django Full Course #2: Setting Up Your Django Environment: Python, VS Code, venv, and Installing Django

Welcome to Part 2 of Django Full Course: Zero to Production. In Part 1 we looked at what Django is, how MVT works, and how Django compares with Flask and FastAPI. Now it's time to get your hands dirty.

Before writing a single line of Django code, you need a clean, reliable development environment. A good setup saves hours of confusing errors later, and it makes your projects easy to share and rebuild on any computer.

By the end of this post you will be able to:

  • Install and verify a reproducible coding environment (Python and VS Code)
  • Isolate dependencies with a virtual environment and export a reproducible requirements.txt
  • Install a compatible Django version and verify that it works

Watch the lessons

This post covers videos 3, 4, and 5 of the course.

Video 3: Install Python, VS Code and Required Extensions

Video 4: Python Virtual Environment, venv, pip and Requirements

Video 5: Install Django and Check Django Version


Part A: Install Python and VS Code

1. Install Python

Django is a Python framework, so Python comes first. Download the latest stable Python 3 release from python.org.

Which Python version? Django supports specific Python versions, and newer Django releases drop support for older Pythons. At the time of writing, the current Django 6.x releases support Python 3.12, 3.13, and 3.14, while Django 5.2 LTS supports Python 3.10 through 3.14. You can always check the official compatibility table in the Django installation FAQ. The simple rule: install a recent, supported Python 3 version.

Windows tip: on the first screen of the installer, tick "Add python.exe to PATH" before you click Install. Forgetting this is the most common beginner problem.

Verify the installation. Open a terminal (Command Prompt, PowerShell, or Terminal) and run:

# Windows
python --version

# macOS / Linux
python3 --version
Enter fullscreen mode Exit fullscreen mode

You should see something like Python 3.x.x. If you do, Python is installed correctly.

2. Install Visual Studio Code

Download VS Code from code.visualstudio.com and install it. It's free, fast, and works on Windows, macOS, and Linux.

3. Add the essential extensions

Open the Extensions panel (Ctrl+Shift+X) and install:

  • Python (by Microsoft): editor support, debugging, and interpreter selection (it also brings Pylance for smarter code suggestions)
  • A Django extension (for example, the one by Baptiste Darthenay): helps with Django template syntax and snippets

These make writing, running, and debugging Django code much easier. You can add more later as you need them.


Part B: Isolate Your Project with a Virtual Environment

Why you need a virtual environment

If you install every package globally, different projects start fighting over versions. One project needs Django 5.2, another needs a newer release, and suddenly something breaks. A virtual environment (venv) gives each project its own private set of packages, so projects never interfere with each other.

4. Create a project folder

mkdir django-course
cd django-course
code .
Enter fullscreen mode Exit fullscreen mode

The last command opens the folder in VS Code. (If code isn't recognized, open VS Code and use File → Open Folder instead.)

5. Create the virtual environment

Open the VS Code terminal (Terminal → New Terminal in the top menu) and run:

# Windows
python -m venv venv

# macOS / Linux
python3 -m venv venv
Enter fullscreen mode Exit fullscreen mode

This creates a venv folder that holds your project's isolated Python.

6. Activate it

# Windows (Command Prompt or PowerShell)
venv\Scripts\activate

# macOS / Linux
source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

When it works, you'll see (venv) at the start of your terminal prompt. That means everything you install now goes into this project only. To leave the environment, run deactivate.

PowerShell error? If Windows blocks the activation script, run this once and try again:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
Enter fullscreen mode Exit fullscreen mode

7. Tell VS Code to use it

Press Ctrl+Shift+P, search for Python: Select Interpreter, and choose the one inside your venv folder. Now VS Code understands the packages you install.

8. Learn the basic pip commands

pip is Python's package installer. These are the commands you'll use all the time:

python -m pip install --upgrade pip   # update pip itself
pip list                              # show installed packages
pip freeze                            # show packages with exact versions
Enter fullscreen mode Exit fullscreen mode

Part C: Install Django and Verify It

9. Install Django

With (venv) active, install Django:

python -m pip install django
Enter fullscreen mode Exit fullscreen mode

This installs the latest Django release that works with your Python version. If you need a specific version (for example, to match a tutorial or a team project), pin it:

python -m pip install "django==5.2.*"
Enter fullscreen mode Exit fullscreen mode

Which one should you pick? Django 5.2 is a long-term support (LTS) release with security updates planned until April 2028, so it's a stable choice for learning and projects. The newest release gives you the latest features. Either is fine for this course, and the code we write works the same way on both. Just make sure your Python version is supported by the Django version you choose.

10. Verify the installation

Check the version in any of these ways:

python -m django --version
django-admin --version
pip show django
Enter fullscreen mode Exit fullscreen mode

Each should print the installed Django version. You can also check from Python itself:

python -c "import django; print(django.get_version())"
Enter fullscreen mode Exit fullscreen mode

If you see a version number and no errors, Django is installed.

11. Export your dependencies to requirements.txt

Now that Django is installed, save your environment so anyone (including future you) can rebuild it exactly:

pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

This writes every installed package and its exact version into requirements.txt. To recreate the environment on another computer, or after deleting venv:

python -m venv venv
# activate the environment, then:
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

That is what reproducible means: the same versions, every time, on every machine.

12. Keep venv out of Git

When you use Git and GitHub, never commit the venv folder. Create a .gitignore file and add:

venv/
__pycache__/
*.pyc
Enter fullscreen mode Exit fullscreen mode

Commit requirements.txt instead. It's small, readable, and enough to rebuild the environment.


Quick troubleshooting

Problem Likely fix
python is not recognized Reinstall Python and tick "Add python.exe to PATH", or try py --version on Windows
(venv) doesn't appear The environment isn't activated. Run the activate command again
pip install puts packages in the wrong place Check that (venv) is active, and use python -m pip install ...
VS Code underlines Django imports Select the venv interpreter with Python: Select Interpreter
Django won't install Check that your Python version is supported by that Django release

Your environment checklist

  • [x] Python 3 installed and verified with --version
  • [x] VS Code installed with the Python and Django extensions
  • [x] Project folder created and opened in VS Code
  • [x] Virtual environment created, activated, and selected as the interpreter
  • [x] Django installed and verified with python -m django --version
  • [x] requirements.txt exported with pip freeze
  • [x] venv/ added to .gitignore

Key takeaways

  • Always create a virtual environment per project to isolate dependencies.
  • Use python -m pip so you know exactly which Python the packages go to.
  • Check Django and Python compatibility before installing.
  • requirements.txt makes your project reproducible on any machine.

What's next

In Part 3, we'll create our first Django project, run the development server, and explore the project and app folder structure. Follow me here on DEV so you don't miss it.

Your turn

Did the setup go smoothly, or did you hit an error? Tell me your operating system and the error message in the comments, and I'll help you fix it!


This post is part of the series **Django Full Course: Zero to Production. Watch the lessons on YouTube: Video 3, Video 4, and Video 5.

Find me on GitHub and LinkedIn.

Top comments (0)