Python Virtual Environment (venv)

A Python Virtual Environment (venv) creates a local environment for your project dependencies (packages), completely detached from the system. This isolates your project's packages from the system's in order to prevent version conflicts, and allows you to keep track of only the requirements your project demands. To set up a local virtual environment, go to your Python project folder, then run:

python -m venv venv/

To activate the new environment:

source venv/bin/activate

To install requirements from a requirements.txt file:

pip install -r requirements.txt

Deactivating a virtual environment

To deactivate a venv and return to the system's python environment:

deactivate