Skip to main content

Install with pip

You need to use pip to install dbt Core on Windows, Linux, or MacOS operating systems.

You can install dbt Core and plugins using pip because they are Python modules distributed on PyPI.

Does my operating system have prerequisites?
What version of Python can I use?

What is a Python virtual environment?

A Python virtual environment creates an isolated workspace for Python projects, preventing conflicts between dependencies of different projects and versions.

You can create virtual environments using tools like conda, poetry or venv. This guide uses venv because it's lightweight, has the fewest additional dependencies, and is included in Python by default.

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

  • Access to a terminal or command prompt.
  • 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.
  • Have the necessary permissions to create directories and install packages on your machine.
  • Once you've met the prerequisites, follow these steps to set up your virtual environment.

Set up a Python virtual environment

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

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

To set up a Python virtual environment, navigate to your project directory and execute the command. This will generate a new virtual environment within a local folder that you can name anything. Our convention has been to name it env or env-anything-you-want

  1. Create your virtual environment:
python3 -m venv env
  1. Activate your virtual environment:
source env/bin/activate
  1. Verify Python Path:
which python
  1. Run Python:
env/bin/python

If you're using dbt Core, refer to What are the best practices for installing dbt Core with pip? after creating your virtual environment.

If you're using the dbt Cloud CLI, you can install dbt Cloud CLI in pip after creating your virtual environment.

Deactivate virtual environment

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

deactivate

Create an alias

To activate your dbt environment with every new shell window or session, you can create an alias for the source command in your $HOME/.bashrc, $HOME/.zshrc, or whichever config file your shell draws from.

For example, add the following to your rc file, replacing <PATH_TO_VIRTUAL_ENV_CONFIG> with the path to your virtual environment configuration.

alias env_dbt='source <PATH_TO_VIRTUAL_ENV_CONFIG>/bin/activate'

Installing the adapter

Once you decide which adapter you're using, you can install using the command line. Beginning in v1.8, installing an adapter does not automatically install dbt-core. This is because adapters and dbt Core versions have been decoupled from each other so we no longer want to overwrite existing dbt-core installations.

For example, if using Postgres:

Upgrade adapters

To upgrade a specific adapter plugin:

python -m pip install --upgrade dbt-ADAPTER_NAME

Install dbt-core only

If you're building a tool that integrates with dbt Core, you may want to install the core library alone, without a database adapter. Note that you won't be able to use dbt as a CLI tool.

python -m pip install dbt-core

Change dbt Core versions

You can upgrade or downgrade versions of dbt Core by using the --upgrade option on the command line (CLI). For more information, see Best practices for upgrading in Core versions.

To upgrade dbt to the latest version:

python -m pip install --upgrade dbt-core

To downgrade to an older version, specify the version you want to use. This command can be useful when you're resolving package dependencies. As an example:

python -m pip install --upgrade dbt-core==0.19.0

pip install dbt

Note that, as of v1.0.0, pip install dbt is no longer supported, will raise an explicit error, and the dbt package on PyPI stopped receiving updates. Since v0.13, PyPI package named dbt was a simple "pass-through" of dbt-core and the four original database adapter plugins.

In the fall of 2023, the dbt package on PyPI became a supported method to install the dbt Cloud CLI.

If you have workflows or integrations that rely on installing the package named dbt, you can achieve the same behavior by installing the same five packages that it used:

python -m pip install \
dbt-core \
dbt-postgres \
dbt-redshift \
dbt-snowflake \
dbt-bigquery \
dbt-trino

Or, better yet, just install the package(s) you need!

0