Using uv in JupyterLab¶
After launching JupyterLab on UCloud, a uv virtual environment can be set up by opening a terminal and following the procedure described in Setting up uv on UCloud.
A new Jupyter kernel corresponding to the uv environment can be added via the command line:
$ source my-name/bin/activate
$ uv pip install ipykernel
$ python -m ipykernel install --user --name my-name --display-name "Python (uv Env)"
Automated Setup¶
A new kernel can also be registered during job startup using the Initialization parameter. Below a minimal working script example:
#!/bin/bash
# Create a new uv virtual environment
uv venv my-name
# Activate the env
source my-name/bin/activate
# Install ipykernel and your desired packages in the uv environment
uv pip install ipykernel numpy scipy
# Register the environment as a JupyterLab kernel
python -m ipykernel install --user --display-name "uv Env"
# Deactivate it
deactivate
Note
When using a uv environment name and path other than /work/.venv
, it is necessary to set in the notebook the VIRTUAL_ENV
variable after starting the new uv kernel:
%set_env VIRTUAL_ENV=/work/my-name
Contents