-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Summary
My understanding from the uv + Jupyter integration doc is that running JupyterLab without adding it to the project dependencies like uv run --with jupyter jupyter lab should make the project's dependencies available in the JupyterLab environment. I see that that works in 0.7.22 but not in 0.8.0. I strongly suspect that the change comes from #14447.
As a minimal example, if I run:
curl -LsSf https://astral.sh/uv/install.sh | sh
uv python install 3.10
uv init --bare --python 3.10
uv add boto3
uv run --with jupyter jupyter lab
Then with 0.7.22 I'm able to run import boto3 successfully in a python cell in a notebook, but not in 0.8.0. In version 0.8.0, when I run the following in a cell:
import sys
print(sys.executable)
print(sys.path)
I get:
/Users/kevin/.cache/uv/archive-v0/clAeKvr1eBVfjXfG8R8TX/bin/python
['/Users/kevin/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python310.zip', '/Users/kevin/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python3.10', '/Users/kevin/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python3.10/lib-dynload', '', '/Users/kevin/.cache/uv/archive-v0/clAeKvr1eBVfjXfG8R8TX/lib/python3.10/site-packages']
While if I run a command like:
!python -c "import sys; print(sys.executable); print(sys.path)"
I get:
/Users/kevin/.cache/uv/builds-v0/.tmp2PZpfe/bin/python
['', '/Users/kevin/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python310.zip', '/Users/kevin/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python3.10', '/Users/kevin/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python3.10/lib-dynload', '/Users/kevin/.cache/uv/builds-v0/.tmp2PZpfe/lib/python3.10/site-packages', '/Users/kebel/source/uv-test/uv-repro/.venv/lib/python3.10/site-packages', '/Users/kevin/.cache/uv/archive-v0/clAeKvr1eBVfjXfG8R8TX/lib/python3.10/site-packages']
The latter contains the desired .../uv-repro/.venv project venv, I believe via a .pth file where the ephemeral .cache/uv/builds-v0/.tmp2PZpfe/bin/python is installed.
I believe the intention is for the kernel to use the same "builds-v0" ephemeral python interpreter location which has the overlay .pth file rather than the "archive-v0" --with python environment. I see that the kernelspec looks like:
{
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3 (ipykernel)",
"language": "python",
"metadata": {
"debugger": true
}
}
The jupyter_client logic is that the "python" command is interpreted as sys.executable, and judging by the output of uv run --with jupyter jupyter troubleshoot, that is the --with environment (/Users/kevin/.cache/uv/archive-v0/clAeKvr1eBVfjXfG8R8TX/bin/python in my case). (The !python and similar commands have the ephemeral env in the $PATH env var though, and thus seem to use the right python environment.)
Platform
macOS 15.5 (also tested in Amazon Linux 2023 and debian:bookworm docker image)
Version
0.8.0
Python version
3.10.18