Repository navigation
Python environments
Each notebook's kernel runs in a Python environment. The header chip shows
which one (● Python 3.12.4 · .venv ▾); its dot is the kernel state (green
ready, yellow starting or installing, red failed) and while the kernel is not
ready the state text, such as the live output of a running install, follows
the environment name.
At start a notebook uses the environment it last used; otherwise the nearest
.venv / venv (next to the file, up to the project root) that has
ipykernel; otherwise gpython's own interpreter. A project venv without
ipykernel is pointed out once.
f6 (or a click on the header chip) opens the environment picker:
-
Switch: every venv, uv env and conda env next to the notebook and in
~/.virtualenvs,~/.venvs, conda'senvs, plus uv's managed Pythons andpython3.xonPATH. Type to filter, or type a path to a venv or a python. Picking a venv without ipykernel installs it first. Picking a bare interpreter offers to make a venv from it. Switching starts a fresh kernel (cells become stale) and is remembered for that notebook. -
New uv env:
uv venv <folder> [--python 3.12], then ipykernel, then switch. Any Python version uv can download works. -
New venv: the same with
python -m venvand pip, no uv needed. -
Install packages:
uv pip installinto the kernel's environment (pip without uv). New imports work without restarting the kernel. -
Add to project:
uv add, writing topyproject.tomland syncing into the kernel's environment.
The same as commands: :env (picker) or :env name|path, :venv [folder] [python], :uv venv [folder] [python], :pip numpy pandas, :pip list,
:pip uninstall x, :uv add httpx, :uv <anything> (runs in the project).
Inside cells, %uv pip install x and %uv add x target the kernel's own
When a cell fails with ModuleNotFoundError, the install
prompt opens at the bottom, prefilled with the package (cv2 becomes
opencv-python, sklearn becomes scikit-learn, from google.cloud import storage becomes google-cloud-storage; the table is packages.json, anything
else installs under its import name). The prompt lists how: uv add (into
pyproject.toml, synced into the env) when the project has one, and
uv pip install (the env only; plain pip without uv). ↑/↓ pick: the
chosen row carries ● and the title shows the exact command enter will
run. The pick is remembered as install_mode; until you pick uv add once,
the default is uv pip install, which touches no project file. enter
installs and runs the cell again;
esc declines. A failed install shows the exact command, its exit code and
what uv or pip said, both as a notification and under the cell. A hint under
the traceback keeps the :pip command, and :pip alone offers the same package.
Running the cell again asks again; only the automatic re-run after an install
leaves out a module that still fails. :set autoinstall installs and re-runs
without asking (a failed install asks on the next run); :set noautoinstall
goes back to the prompt.
Standard-library modules the interpreter was built without are pointed out
instead.
Use the notebook
- Getting started
- Command line
- Running cells
- Keys
- Commands
- Vim
- Markdown cells
- Variables and the debugger
- Images
Set up the workspace
Help and project