Contents

Python Virtual Environments Explained

Python Virtual Environments Explained

If you’ve ever broken a project by upgrading a package globally, you need venvs.

What is a venv?

A virtual environment is an isolated Python installation — it has its own pip and packages, completely separate from your system Python.

Creating one

python -m venv .venv
source .venv/bin/activate    # Linux/macOS
.venv\Scripts\activate       # Windows

Installing packages

pip install requests numpy pandas
pip freeze > requirements.txt

Restoring later

python -m venv .venv
pip install -r requirements.txt

Using with conda

If you use conda, each conda create -n myenv python=3.11 works the same way — isolated by default.

Rule of thumb

One project → one environment. Always.