-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d328a4
commit 38f0dc1
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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
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,45 @@ | ||
# Using uv with Jupyter | ||
|
||
## As a standalone tool... | ||
|
||
If you're working within a [project](../../concepts/projects.md), you can kick off a Jupyter server | ||
with access to the project's virtual environment via the following: | ||
|
||
```console | ||
$ uv run --with jupyter jupyter notebook | ||
``` | ||
|
||
Within the notebook, you can then import your project's modules as you would in any other `uv run` | ||
invocation. For example, if your project depends on `requests`, `import requests` will import | ||
`requests` from the project's virtual environment. | ||
|
||
While `jupyter` itself is installed in an isolated environment when used via | ||
`uv run --with jupyter`, within the notebook, `!uv add` and related commands will modify the | ||
_project's_ environment. | ||
|
||
For example, running `!uv add pydantic` from within a notebook will add `pydantic` to the project's | ||
dependencies and virtual environment, such that `import pydantic` will work immediately, without | ||
further configuration or a server restart. | ||
|
||
!!! note | ||
|
||
Since the Jupyter server is running in an isolated virtual environment, `!uv pip install` will install package's | ||
into _Jupyter's_ environment, not the project environment. Such dependencies may disappear on subsequent `jupyter` | ||
invocations. To install packages into the project environment, use `!uv add`. | ||
|
||
If you're working with a notebook that relies on pip (e.g., via the `%pip` magic), you can include | ||
pip in your project's virtual environment by running `uv venv --seed` prior to starting the Jupyter | ||
server. For example, given: | ||
|
||
```console | ||
$ uv venv --seed | ||
$ uv run --with jupyter jupyter notebook | ||
``` | ||
|
||
Subsequent `%pip install` invocations within the notebook will install packages into the project's | ||
virtual environment. However, such modifications will _not_ be reflected in the project's | ||
`pyproject.toml` or `uv.lock` files. | ||
|
||
## As a project dependency... | ||
|
||
## Within VS Code... |
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