Python Virtual Environments Explained
Contents
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 # WindowsInstalling packages
pip install requests numpy pandas
pip freeze > requirements.txtRestoring later
python -m venv .venv
pip install -r requirements.txtUsing 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.

