Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a Python virtual environment #6681

Merged
merged 29 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a298b32
Create a Python virtual environment
nataliefiann Dec 17, 2024
89b960e
Merge branch 'nfiann-prerelease' into new-branch-name-VE
mirnawong1 Dec 19, 2024
ee5f283
Merge branch 'nfiann-prerelease' into new-branch-name-VE
mirnawong1 Dec 19, 2024
7c89426
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Dec 20, 2024
544cce2
Added tabs
nataliefiann Dec 20, 2024
1c6b1de
Merge branch 'new-branch-name-VE' of https://github.com/dbt-labs/docs…
nataliefiann Dec 20, 2024
4fd2cd2
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Dec 23, 2024
75c8a35
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Dec 23, 2024
5ecbad2
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Dec 23, 2024
749d9b8
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Dec 23, 2024
322359d
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Dec 23, 2024
867ccfc
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Dec 23, 2024
e16c8bf
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Dec 23, 2024
46222c3
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Dec 23, 2024
568191f
Merge branch 'nfiann-prerelease' into new-branch-name-VE
nataliefiann Dec 23, 2024
bc1fcb7
rendered examples
nataliefiann Dec 30, 2024
b0f3b61
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann Jan 6, 2025
5a11611
Merge branch 'nfiann-prerelease' into new-branch-name-VE
nataliefiann Jan 6, 2025
b326b08
Merge branch 'nfiann-prerelease' into new-branch-name-VE
nataliefiann Jan 24, 2025
65346ff
Updated PR
nataliefiann Jan 24, 2025
f30f4cb
Update website/docs/docs/core/pip-install.md
nataliefiann Jan 24, 2025
e987de6
rolled in feedback
nataliefiann Jan 24, 2025
8ee97f3
added code blocks and webaite links
nataliefiann Jan 24, 2025
6c84676
Merge branch 'nfiann-prerelease' into new-branch-name-VE
mirnawong1 Jan 24, 2025
4f1ae53
Update website/docs/docs/core/pip-install.md
nataliefiann Jan 24, 2025
5d6322e
Amended Headers
nataliefiann Jan 27, 2025
694f51e
Update website/docs/docs/core/pip-install.md
nataliefiann Jan 27, 2025
efb8725
Updated prerequisites
nataliefiann Jan 27, 2025
bbc3290
Merge branch 'current' into new-branch-name-VE
nataliefiann Jan 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 89 additions & 15 deletions website/docs/docs/core/pip-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,98 @@ You can install dbt Core and plugins using `pip` because they are Python modules
<FAQ path="Core/install-pip-os-prereqs" />
<FAQ path="Core/install-python-compatibility" />

### Using virtual environments
## What is a Python virtual environment?
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

We recommend using virtual environments (venv) to namespace pip modules.
A Python virtual environment creates an isolated workspace for Python projects, preventing conflicts between dependencies of different projects and versions.

1. Create a new venv:
You can create virtual environments using tools like [conda](https://anaconda.org/anaconda/conda), [poetry](https://python-poetry.org/docs/managing-environments/) or `venv`. This guide uses `venv` because it's lightweight, has the fewest additional dependencies, and is included in Python by default.

```shell
python -m venv dbt-env # create the environment
```
Users who want to run dbt locally, for example in [dbt Core](/docs/core/installation-overview) or the [dbt Cloud CLI](/docs/cloud/cloud-cli-installation#install-a-virtual-environment) may want to install a Python virtual environment.

### Prerequisites

Once you've met the prerequisites, follow these steps to set up your virtual environment.
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

- Access to a terminal or command prompt.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Access to a terminal or command prompt.
Once you've met the prerequisites, follow these steps to set up your virtual environment.
- Access to a terminal or command prompt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops i mean to put this sugg in line 30!

- Have [Python](https://www.python.org/downloads/) 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](https://pip.pypa.io/en/stable/installation/). 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.

### 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](https://github.com/dbt-labs/dbt-core/blob/main/CONTRIBUTING.md#virtual-environments) has been to name it `env` or `env-anything-you-want`

<Tabs>
<TabItem value="Unix/macOS" label="Unix/macOS">
1. Create your virtual environment:

```shell
python3 -m venv env
```

2. Activate your virtual environment:

```shell
source env/bin/activate
```

3. Verify Python Path:

```shell
which python
```

2. Activate that same virtual environment each time you create a shell window or session:
4. Run Python:

```shell
env/bin/python
```
</TabItem>

<TabItem value="Windows" label="Windows">
1. Create your virtual environment

```shell
py -m venv env
```

2. Activate your virtual environment:

```shell
env\Scripts\activate
```

3. Verify Python Path:

```shell
where python
```

4. Run Python:

```shell
env\Scripts\python
```
</TabItem>
</Tabs>

If you're using dbt Core, refer to [What are the best practices for installing dbt Core with pip?](/faqs/Core/install-pip-best-practices.md#using-virtual-environments) after creating your virtual environment.
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

If you're using the dbt Cloud CLI, you can [install dbt Cloud CLI in pip](/docs/cloud/cloud-cli-installation#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:

```shell
source dbt-env/bin/activate # activate the environment for Mac and Linux OR
dbt-env\Scripts\activate # activate the environment for Windows
deactivate
```

#### Create an alias
### 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.

Expand All @@ -37,7 +111,7 @@ For example, add the following to your rc file, replacing `<PATH_TO_VIRTUAL_ENV_
alias env_dbt='source <PATH_TO_VIRTUAL_ENV_CONFIG>/bin/activate'
```

### Installing the adapter
## Installing the adapter

Once you decide [which adapter](/docs/supported-data-platforms) 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.

Expand Down Expand Up @@ -119,7 +193,7 @@ If you're building a tool that integrates with dbt Core, you may want to install
python -m pip install dbt-core
```

### Change dbt Core versions
## Change dbt Core versions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [vale] reported by reviewdog 🐶
[custom.SentenceCaseHeaders] 'Change dbt Core versions' should use sentence-style capitalization. Try 'Change dbt core versions' instead.


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](/docs/dbt-versions/core#best-practices-for-upgrading).

Expand All @@ -135,7 +209,7 @@ To downgrade to an older version, specify the version you want to use. This comm
python -m pip install --upgrade dbt-core==0.19.0
```

### `pip install dbt`
## `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.

Expand All @@ -157,7 +231,7 @@ Or, better yet, just install the package(s) you need!

<VersionBlock firstVersion="1.8">

### Installing prereleases
## Installing prereleases

A prerelease adapter is a version released before the final, stable version. It allows users to test new features, provide feedback, and get early access to upcoming functionality &mdash; ensuring your system will be ready for the final release.

Expand Down Expand Up @@ -192,7 +266,7 @@ dbt --version
```
Note, this will also install any pre-releases of all dependencies.

#### Activate your virtual environment
### Activate your virtual environment

To install or use packages within your virtual environment:

Expand Down
42 changes: 26 additions & 16 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ const sidebarSettings = {
link: { type: "doc", id: "docs/core/installation-overview" },
items: [
"docs/core/installation-overview",
"docs/core/pip-install",
"docs/core/docker-install",
"docs/core/pip-install",
"docs/core/source-install",
],
},
Expand Down
Loading