Virtual environments isolate project dependencies—each venv has its own python and pip. Modern workflows also use pyproject.toml with tools like Poetry or uv locally; venv remains the stdlib baseline.
Workflow recap
python3 -m venv .venv- Activate (
source .venv/bin/activateon macOS/Linux) pip install -r requirements.txt- Run tests and apps with the venv Python
Why isolation matters
Project A may need Django 4.2 while Project B needs Django 5.x—global installs create dependency hell. Same lesson as node_modules per app in JavaScript.
Important interview questions and answers
- Q: venv vs Docker?
A: venv isolates Python packages on one machine; Docker isolates OS-level runtime and system deps for deploy parity. - Q: How know active venv?
A: Prompt prefix(.venv)andwhich pythonpoints inside the venv directory.
Self-check
- What module creates a venv?
- Why not install all projects into system Python?
Tip: Commit requirements.txt or lockfile—not the .venv folder itself.
Interview prep
- venv vs Docker?
venv isolates Python packages; Docker isolates OS/runtime for deploy parity.
- Detect active venv?
Shell prompt prefix and
which pythoninside .venv/bin.