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

Open
wants to merge 18 commits into
base: nfiann-prerelease
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 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
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
72 changes: 72 additions & 0 deletions website/docs/docs/core/create-a-python-virtual-environment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: Create a Python Virtual Environment
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
id: create-a-python-virtual-environment
description: "Instructions on creating a Python virtual environment."
pagination_next: "docs/core/create-a-python-virtual-environment"
pagination_prev: null
---

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](https://anaconda.org/anaconda/conda), [poetry](https://python-poetry.org/docs/managing-environments/), 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.
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

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

- 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`.
- Access to a terminal or command prompt.
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
- Have the necessary permissions to create directories and install packages on your machine.

## Install a Python virtual environment

Check warning on line 25 in website/docs/docs/core/create-a-python-virtual-environment.md

View workflow job for this annotation

GitHub Actions / vale

[vale] website/docs/docs/core/create-a-python-virtual-environment.md#L25

[custom.SentenceCaseHeaders] 'Install a Python virtual environment' should use sentence-style capitalization. Try '' instead.
Raw output
{"message": "[custom.SentenceCaseHeaders] 'Install a Python virtual environment' should use sentence-style capitalization. Try '' instead.", "location": {"path": "website/docs/docs/core/create-a-python-virtual-environment.md", "range": {"start": {"line": 25, "column": 4}}}, "severity": "WARNING"}

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`:
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

<Expandable alt_header="Unix/macOS" >
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved

1. Create your virtual environment

```shell
python3 -m venv .venv
```

2. Activate your virtual environment:

```shell
source .venv/bin/activate
which python
.venv/bin/python
```
</Expandable>

<Expandable alt_header="Windows" >

1. Create your virtual environment

```shell
py -m venv .venv
```

2. Activate your virtual environment:

```shell
.venv\Scripts\activate
where python
.venv\Scripts\python
```

</Expandable>

nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
## Deactivate virtual environment

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

```shell
deactivate
```
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const sidebarSettings = {
label: "Install dbt Core",
link: { type: "doc", id: "docs/core/installation-overview" },
items: [
"docs/core/create-a-python-virtual-environment",
nataliefiann marked this conversation as resolved.
Show resolved Hide resolved
"docs/core/installation-overview",
"docs/core/pip-install",
"docs/core/docker-install",
Expand Down
Loading