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
| Command | What it does |
|---|---|
python3 -m venv .venv | Create an environment in .venv |
source .venv/bin/activate | Activate it (Windows: .venv\Scripts\activate) |
pip install -r requirements.txt | Reproducible installs |
pip freeze > requirements.txt | Snapshot exact versions |
deactivate | Leave 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.
Perguntas frequentes
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.