Skip to content
Rochester, NY design, systems, study tools, and experiments Built in public

Python virtual environments with venv

Per-project isolation for Python dependencies using the built-in venv module. Covers creation, activation across OSes, and freezing to requirements.txt.

python python tooling dependencies 2026-04-15

Virtual environments isolate project dependencies, preventing conflicts between different Python projects that may require different library versions. This ensures reproducibility and clean deployments.

To create an environment, use python -m venv <env_name> (on systems where python resolves to Python 3; otherwise python3 -m venv <env_name>). Activation varies by OS:

  • Windows (PowerShell): .\<env_name>\Scripts\Activate.ps1
  • Windows (cmd / Git Bash): .\<env_name>\Scripts\activate
  • macOS / Linux: source <env_name>/bin/activate

Once activated, pip install <package> installs dependencies into the environment instead of the system Python. To record the exact state of installed packages for later use, generate a requirements.txt file:

pip freeze > requirements.txt

This file lists all installed packages and their pinned versions, allowing others to recreate the environment accurately with pip install -r requirements.txt.