This guide explains how to set up a dedicated Jupyter kernel for your uv project that uses the project's own virtual environment (.venv).
1. Install ipykernel as a Development Dependency
First, ensure that your project has ipykernel installed so that it can create kernels for Jupyter.
-
--dev: installs it as a development dependency. -
ipykernel: the package that allows creating Jupyter kernels.
2. Create a Jupyter Kernel for Your Project's .venv
Run the following command to register a Jupyter kernel that points to the project's virtual environment:
Explanation of the command:
-
uv run ipython kernel install: runs the IPython kernel installation inside theuvenvironment. -
--user: installs the kernel only for the current user. -
--env VIRTUAL_ENV=$(pwd)/.venv: points the kernel to use your project's virtual environment located at.venv. -
--name=project: the name of the kernel that will appear in Jupyter.
3. Reload VS Code (if using VS Code)
After creating the kernel, reload your VS Code window to make it available:
-
Press
Ctrl+Shift+P(orCmd+Shift+Pon Mac) to open the Command Palette. -
Type
Reload Windowand hitEnter.
4. Select the Kernel in Jupyter Notebook or VS Code
-
Open your Jupyter notebook.
-
Click on the kernel name (top right corner) or
Select Kernel. -
Choose the newly created kernel
project.
Notes
-
Make sure your
.venvis already created and has Python installed. -
Using this method ensures that the notebook runs in the same environment as your
uvproject. -
This is especially useful when working with isolated dependencies for different projects.
No comments:
Post a Comment