The short answer
A virtual environment is an isolated directory that contains a Python interpreter plus its own site-packages. Projects get separate dependency sets so Package A for Project 1 does not conflict with Package B for Project 2, and you do not pollute the system Python.
Common tools: venv (stdlib), virtualenv, poetry, uv, conda (broader env management).
# Shell examples (not Python code executed by the interpreter)
# python -m venv .venv
# source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windows
# pip install -r requirements.txt
# deactivateWhat isolation gives you:
- Per-project package versions
- Reproducible installs via
requirements.txt/ lockfiles - Safer experimentation without breaking global tools
Interview tip: Pair "virtual env" with "pin dependencies" and "don't install into system Python for app work."