Blog › Python · Published 2026-11-26

Python virtual environments with venv: the practical guide

Installing every project's packages into one global Python is how version conflicts begin. The standard library's answer is venv: lightweight virtual environments, each with its own independent set of installed packages. This is the practical guide, from the official Python documentation.

What a virtual environment is

Per the Python docs: a virtual environment is created on top of an existing Python installation (its "base" Python) and is by default isolated from the base environment's packages, so only what you explicitly install inside it is available. Conventionally it lives in a directory named .venv or venv in your project.

Create one

python -m venv .venv

The docs explain what this creates: the target directory with a pyvenv.cfg file pointing at the base Python, a bin subdirectory (or Scripts on Windows) with the Python executable, and a lib/pythonX.Y/site-packages directory for the environment's own packages.

Activate it

# Linux / macOS
source .venv/bin/activate

# Windows (Command Prompt)
.venv\Scripts\activate.bat

After activation, python and pip resolve to the environment's copies, so pip install touches only this project.

Why bother

Common mistakes

Next steps: build your first Flask web app and read and write JSON files in Python.

Official sources

Need help with your project?
We build websites, systems and automation. Start your project WhatsApp

All articles