Skip to main content

Create a Python virtual environment

A Python virtual environment is an isolated workspace for Python projects. This prevents libraries and versions used in one project from interfering with others, making it especially helpful when working on multiple projects with differing requirements or avoiding conflicts with global Python installations.

The Python ecosystem offers several tools for creating isolated environments, such as conda, poetry, and venv. Among these, venv has the fewest additional dependencies and has been included by default in recent Python versions for quite some time.

venv will set up a Python virtual environment within the .venv folder.

Users who want to run dbt locally, for example in dbt Core or the dbt Cloud CLI may want to install a Python virtual environment.

Prerequisites

  • Have Python installed on your machine. You can check if Python is installed by running python --version or python3 --version in your terminal or command prompt.
  • Have pip installed. You can check if pip is installed by running pip --version or pip3 --version.
  • Access to a terminal or command prompt.
  • Have the necessary permissions to create directories and install packages on your machine.

Install a Python virtual environment

Depending on the operating system you use, you'll need to execute specific steps to set up a virtual environment.

To install a Python virtual environment, navigate to your project directory and execute the command. This will generate a new virtual environment within a local folder named venv:

 Unix/macOS
 Windows

Deactivate virtual environment

To switch projects or leave your virtual environment, deactivate the environment using the command while the virtual environment is active:

deactivate
0