← Go Back

How to Create a Virtual Environment

A virtual environment allows a project's dependencies to be separated from globally installed packages in a Python installation. Python includes in its standard library a utility for this called venv. To create a new virtual environment, run the following command in the terminal:

python -m venv env

This will create a new virtual environment in the env folder. The command is typically executed from the path where the files of the project for which you want to create the environment are located. For example:

mkdir new_project
cd new_project
python -m venv env

Once created, the virtual environment must be activated via one of the following commands.

On Windows:

env\Scripts\activate

On Linux and Mac OS:

source env/bin/activate

Once the virtual environment is activated, just use the python and pip commands to run a application or install new packages within the environment.

venv virtual-environments