WIPIVERSE All articles

Virtual environment

Virtual environment is a term used in computing in several related but distinct senses. Its meaning depends on context, and no single definition covers all usages.

Principal senses

1. Networked or simulated interactive environment. In human–computer interaction and virtual reality research, a virtual environment is a computer-generated or networked space in which a user interacts with a computing environment and, in multi-user cases, with other users. Email, chat, and web-based document-sharing systems have been described as early examples, while systems that produce a psychological sense of "being inside" the environment are termed immersive virtual environments (Blascovich, 2002). Wikipedia's article on the term defines it narrowly in this sense and carries maintenance notices indicating that its sourcing is incomplete.

2. Virtualized machine environment. Reference works such as PC Magazine's encyclopedia use "virtual environment" to denote a computer running under a virtual machine — that is, the combination of a virtual machine monitor (hypervisor) and the underlying hardware platform. In this usage the phrase overlaps with the broader concepts of virtualization and virtual machines, in which physical computing resources are divided among multiple isolated execution contexts, each potentially running its own operating system.

3. Software dependency-isolation environment. In software development, and especially in the Python ecosystem, a virtual environment is an isolated directory containing a specific interpreter and a project-specific set of installed packages, kept separate from the system-wide installation and from other projects' environments. This mechanism addresses dependency conflicts and permits package installation without administrator privileges.

Python virtual environments

Python's implementation is the most formalized. PEP 405 ("Python Virtual Environments", authored by Carl Meyer, accepted 2012, implemented in Python 3.3) standardized the mechanism, drawing on the earlier third-party tool virtualenv by Ian Bicking.

Per PEP 405, a virtual environment in its simplest form consists of a copy or symbolic link of the Python binary, a site-packages directory, and a pyvenv.cfg file containing a home key that points to the base Python installation. The environment shares the base installation's standard library but has its own independent set of installed packages. By default it is fully isolated from system-level site-packages; the include-system-site-packages key in pyvenv.cfg can relax this.

At runtime, an interpreter is detected as running inside a virtual environment when sys.prefix differs from sys.base_prefix. Environments are created with the standard-library venv module (python -m venv <path>), conventionally placed in a directory named .venv or venv. They are intended to be disposable and are normally excluded from version control; because installed script "shebang" lines contain absolute interpreter paths, environments are generally non-portable and should be recreated rather than moved.

Activation scripts (activate on POSIX shells, Activate.ps1 or activate.bat on Windows) prepend the environment's binary directory to PATH. Activation is optional, however, and for this reason the presence of the VIRTUAL_ENV environment variable cannot reliably be used to determine whether a program is running in a virtual environment.

Related concepts

The term is sometimes used interchangeably with, but is not identical to, several neighboring terms:

  • Virtual machine — an emulated or virtualized computer system; the substrate of sense 2.
  • Virtualization — the general technology of dividing physical computing resources into virtual ones.
  • Container — an operating-system-level isolation mechanism, distinct from both virtual machines and Python-style virtual environments.
  • Virtual reality — the immersive-interaction domain most closely associated with sense 1.

Disambiguation note

Because the phrase is applied to at least three unrelated technologies, its interpretation depends on the field in which it appears. In packaging and developer documentation it almost always means sense 3; in virtualization and systems administration, sense 2; and in virtual-reality and human–computer-interaction literature, sense 1.

Browse

More topics to explore

    Browse all articles