Virtual environment

An isolated Python environment with its own installed packages, separate from the system Python.

A virtual environment is a private folder holding its own Python and its own installed packages. Creating one per project keeps each project's dependencies separate, so upgrading a package for one project can't break another.

Create one with python -m venv .venv, then activate it before installing anything with pip. Your shell prompt usually changes to show it's active.

Example
python -m venv .venv              # create it
source .venv/bin/activate         # activate (Windows: .venv\Scripts\activate)
pip install flask                 # installs only inside this environment

Where this shows up in real Python

A virtual environment keeps each project’s packages separate, so upgrading one project can’t break another.

Commonly used Virtual environment tools

  • python -m venv .venv — create one in the project folder
  • source .venv/bin/activate — activate it (macOS/Linux)
  • deactivate — step back out
  • which python — confirm which Python is active

Official documentation: Python Library Reference: venv

Related lessons