Setup Venv
Create and activate a virtual environment with venv to isolate project dependencies. Covers basic commands, where the venv lives, and quick notes on pyenv/Poetry alternatives.
1. Introduction
A virtual environment is an isolated folder that holds Python and all the packages your project needs. When you install Django inside a virtual environment, it stays completely separate from other projects and from your system Python.
This page shows you how to create and activate a virtual environment using Python's built-in venv module. No extra tools to install — it comes with Python 3.11.
- Python 3.11 must already be installed on your machine. If not, go back to Install Python first.
- Know how to open a terminal or command prompt on your system.
- Have a folder where you plan to keep your Django project.
- Windows:
.venv\Scripts\activate - macOS or Linux:
source .venv/bin/activate
(.venv) at the start, you are good to go.
2. What is a virtual environment
When you install a package with pip, it installs globally by default — meaning every project on your machine shares the same packages. This causes problems when different projects need different versions of the same package.
A virtual environment solves this by giving each project its own isolated space. Inside .venv, you get:
- A copy of the Python interpreter (3.11 in our case)
- Its own
pipfor installing packages - A
site-packagesfolder where installed packages live
3. Why we use .venv
You will see different names used for virtual environment folders — venv, env, .env, or .venv. We use .venv because:
- It is the Python standard — the official Python docs and PEP 8 recommend
.venv. - Hidden by default — the dot prefix hides it in file explorers and terminals, keeping your project folder clean.
- Widely recognized — editors like VS Code detect and activate
.venvautomatically. - Safe to ignore — most
.gitignoretemplates already exclude.venvfrom version control.
.venv folder to Git. It is large, machine-specific, and not needed — your requirements.txt file is what others use to recreate it.
4. Create the virtual environment
First, open your terminal and navigate to your project folder. If you do not have one yet, create it now. We will create the actual Django project inside this folder in the next tutorial.
Windows
# Create your project folder and enter it
mkdir myproject
cd myproject
# Create the virtual environment using Python 3.11
py -3.11 -m venv .venv
macOS
# Create your project folder and enter it
mkdir myproject
cd myproject
# Create the virtual environment using Python 3.11
python3.11 -m venv .venv
Linux
# Create your project folder and enter it
mkdir myproject
cd myproject
# Create the virtual environment using Python 3.11
python3.11 -m venv .venv
After running this, you will see a .venv folder inside myproject. That folder contains everything the environment needs — do not edit files inside it manually.
5. Activate the virtual environment
Creating the environment is not enough — you need to activate it. Activation tells your terminal to use the Python and pip inside .venv instead of the global ones.
Windows (Command Prompt)
.venv\Scripts\activate
Windows (PowerShell)
.venv\Scripts\Activate.ps1
macOS and Linux
source .venv/bin/activate
Once activated, your terminal prompt will change to show (.venv) at the start:
(.venv) myproject $
This tells you the environment is active. Any package you install with pip now goes into .venv only — not your system.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
6. Verify the environment
With the environment active, confirm you are using the right Python and pip:
python --version
# Expected output: Python 3.11.10
pip --version
# Expected output: pip 24.x.x from .../myproject/.venv/... (python 3.11)
Notice that inside an active virtual environment you use python and pip directly — no need for python3.11 or pip3. The environment handles it.
7. Deactivate the environment
When you are done working on the project, you can deactivate the environment. This works the same on all operating systems:
deactivate
Your prompt will go back to normal. To work on the project again, just activate it again using the command from section 5.
8. Next steps
Your virtual environment is ready and active. The next step is to install Django inside it. Because the environment is isolated, Django will only be available to this project — exactly what we want.