Python Venv and Environments

Isolate dependencies per project with venv and pinned requirements.

  • python venv
  • virtualenv
  • requirements.txt
  • pip freeze
  • activate venv

Python Venv and Environments

Isolate dependencies per project with venv and pinned requirements.

Commands

CommandWhat it does
python3 -m venv .venvCreate an environment in .venv
source .venv/bin/activateActivate it (Windows: .venv\Scripts\activate)
pip install -r requirements.txtReproducible installs
pip freeze > requirements.txtSnapshot exact versions
deactivateLeave the environment

Example

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip freeze | head

FAQ

venv vs conda?

venv is stdlib and light (pure Python); conda manages non-Python binaries too (CUDA, GDAL).

Should .venv be committed?

No — commit requirements.txt (or a lock file); each machine builds its own .venv.

Preguntas frecuentes

venv vs conda?
venv is stdlib and light (pure Python); conda manages non-Python binaries too (CUDA, GDAL).
Should .venv be committed?
No — commit requirements.txt (or a lock file); each machine builds its own .venv.

Python