Virtual Environment (Python)

A virtual environment is an isolated Python setup for a single project, with its own installed packages. It keeps each project's dependencies separate so they don't conflict.

Python

You create one with the venv module that comes with Python. Activating it makes python and pip in that terminal the environment's own, and the environment's python works without activating too. Python's documentation recommends a virtual environment for each project.

Syntax

python -m venv venv
source venv/bin/activate

Examples

Python

python -m venv venv
source venv/bin/activate
pip install flask

Output:

(venv) $ ...

Learn it in a lesson

See also

Back to the Dictionary