-
Notifications
You must be signed in to change notification settings - Fork 978
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
nataliefiann
wants to merge
16
commits into
nfiann-prerelease
Choose a base branch
from
new-branch-name-VE
base: nfiann-prerelease
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a298b32
Create a Python virtual environment
nataliefiann 89b960e
Merge branch 'nfiann-prerelease' into new-branch-name-VE
mirnawong1 ee5f283
Merge branch 'nfiann-prerelease' into new-branch-name-VE
mirnawong1 7c89426
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann 544cce2
Added tabs
nataliefiann 1c6b1de
Merge branch 'new-branch-name-VE' of https://github.com/dbt-labs/docs…
nataliefiann 4fd2cd2
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann 75c8a35
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann 5ecbad2
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann 749d9b8
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann 322359d
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann 867ccfc
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann e16c8bf
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann 46222c3
Update website/docs/docs/core/create-a-python-virtual-environment.md
nataliefiann 568191f
Merge branch 'nfiann-prerelease' into new-branch-name-VE
nataliefiann bc1fcb7
rendered examples
nataliefiann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
website/docs/docs/core/create-a-python-virtual-environment.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
title: Create a Python virtual environment | ||
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 `env` folder. | ||
|
||
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 | ||
|
||
- Access to a terminal or command prompt. | ||
- 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. | ||
|
||
## 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 which you can name it anything you want. [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 .venv/bin/activate | ||
nataliefiann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
which python | ||
.venv/bin/python | ||
nataliefiann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
</TabItem> | ||
|
||
<TabItem value="Windows" label="Windows"> | ||
1. Create your virtual environment | ||
|
||
```shell | ||
py -m venv .venv | ||
nataliefiann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
2. Activate your virtual environment: | ||
|
||
```shell | ||
.venv\Scripts\activate | ||
nataliefiann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
where python | ||
.venv\Scripts\python | ||
nataliefiann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
</TabItem> | ||
</Tabs> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
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. | ||
|
||
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. | ||
|
||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which you can name it anything you want
->that you can name anything
.A suggestion on refining the literature.