Glossary

Virtual Environment

Also known as: venv, virtualenv

A virtual environment is a self-contained directory tree containing a Python installation and a set of installed packages, isolated from the system Python and from other projects. Each virtual environment has its own site-packages directory, so packages installed in one environment do not affect others. This solves the "dependency hell" problem where different projects require different (possibly conflicting) versions of the same package.

The standard tool for creating virtual environments is venv, a module included with Python 3.3+. Running python -m venv .venv creates a new environment in the .venv directory. You activate it with source .venv/bin/activate (macOS/Linux) or .venv\Scripts\activate (Windows). Once activated, python and pip point to the environment's copies. Deactivate with the deactivate command.

Virtual environments are considered essential for professional Python development. They should be created per-project and never committed to version control (add .venv/ to .gitignore). Alternative tools include virtualenv (a third-party precursor to venv with extra features), conda (popular in data science, manages non-Python dependencies too), Poetry (combines dependency management with virtualenvs), and uv (a fast modern alternative that handles both virtualenv creation and package installation).

Related terms: pip, pyproject.toml

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.