Repaso
EspaƱol
PythonCorePY-58

What is a virtual environment (python -m venv .venv) for?

Options

  1. Running Python code inside the browser without installing it
  2. An isolated set of packages per project, so versions do not conflict (Correct option)
  3. A faster interpreter that compiles your code to machine code
  4. A Docker container that holds the whole project and its OS

Answer

An isolated set of installed packages per project, so projects do not conflict on library versions

Why

Project A may need Django 4 while project B needs Django 5. If both install into the same global Python, they clash.

A virtual environment gives each project its own folder of packages. After activating it, pip install installs only there.

List the versions in requirements.txt or pyproject.toml so others can recreate it.

Remember

One virtual environment per project.

Key terms

Practice this question in Repaso