Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What is a virtual environment?

Python · Fundamentals & Gotchas

What is a virtual environment?

Easypython-39
venvvirtualenvdependenciespackaging

Question

What is a virtual environment in Python?

Solution

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
# deactivate

What 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."

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext