Skip to content

Python environments

igaurab edited this page Nov 18, 2026 · 2 revisions

The kernel of each notebook runs in a Python environment. An environment is a Python program together with its installed packages, for example a .venv folder.

The kernel label

The header shows the environment of the kernel, for example ● Python 3.12.4 · .venv ▾.

Dot color Kernel state
Green Ready
Yellow Starting, or installing packages
Red Failed

While the kernel is not ready, the label also shows the state text. During an installation, this is the live output of the installer.

Which environment a notebook starts in

gpython uses the first item that applies:

  1. The uv project, if you gave uv flags on the command line (--extra, --with, …).
  2. The environment that this notebook used last.
  3. The nearest .venv or venv folder that has ipykernel. gpython searches from the folder of the file up to the project root.
  4. The uv project, through uv run --with ipykernel, if the project environment exists.
  5. The Python of gpython itself.

The project root is the nearest folder, at or above the notebook, that has pyproject.toml, uv.lock or .git.

gpython does not install something into a project to select it. It shows a message instead:

Condition Message tells you to
A project environment has no ipykernel Press f6. gpython then installs ipykernel there
A uv project has no environment yet Run uv sync there, or start gpython with --extra or --with

uv projects

A uv project is a folder with a pyproject.toml file, on a computer that has uv.

  • gpython starts the kernel with uv run --with ipykernel.
  • uv installs what the project declares. It removes nothing.
  • ipykernel comes from the cache of uv. It does not go into the project.
  • The environment folder is .venv in the project, or the folder in UV_PROJECT_ENVIRONMENT.
Task How
Install what the project declares :sync
Install an extra or a dependency group :sync NAME
Give uv flags for one session uv flags on the command line

gpython saves the extras and groups that :sync installed. It gives them to uv on later starts.

The environment picker

Open the picker with f6, :env, or a click on the kernel label. Type to filter the list. You can also type the path to an environment folder or to a Python program.

Actions

Action What it does
Change environment Starts a new kernel in the selected environment. All cells become stale. gpython saves the selection for this notebook
New uv environment Runs uv venv <folder> [--python 3.12], installs ipykernel, then changes to it. uv can download the Python version
New venv environment The same with python -m venv and pip. It does not need uv
Install packages uv pip install into the environment of the kernel (pip if there is no uv). New imports work and the kernel does not restart
Add to project uv add. It writes to pyproject.toml and installs into the environment of the kernel
Restart the kernel Same environment, new process
  • If you select an environment that has no ipykernel, gpython installs ipykernel first.
  • If you select a Python program that is not in an environment, gpython offers to make an environment from it.

Where the picker searches

Type Locations
Project environments Adjacent to the notebook, up to the project root
Active environments VIRTUAL_ENV, CONDA_PREFIX
Environment folders WORKON_HOME, ~/.virtualenvs, ~/.venvs, ~/.local/share/virtualenvs
conda The envs folder of ~/miniconda3, ~/anaconda3, ~/miniforge3, ~/mambaforge, ~/.conda
Python versions of uv UV_PYTHON_INSTALL_DIR, or ~/.local/share/uv/python
System Python Each python3 and python3.x on PATH

Commands

Command Action
:env Open the picker
:env name, :env path Change to that environment
:venv [folder] [python] Make an environment with python -m venv and use it
:uv venv [folder] [python] Make an environment with uv and use it
:pip numpy pandas Install packages
:pip Offer the packages that this cell needs
:pip list List the installed packages
:pip uninstall x Remove a package
:uv add httpx Add a package to the project
:uv <other> Run a different uv command in the project
:sync [name ...] Install what the uv project declares

Magics in cells

Magic Action
%uv pip install x Install into the environment of the kernel
%uv add x, %uv remove x, %uv sync Change the project, with the environment of the kernel
%pip install x Uses uv when the environment has no pip

Missing modules

When a cell fails with ModuleNotFoundError, gpython opens an install prompt at the bottom of the screen.

The package name

gpython fills in the package name. For most modules, it is the import name. Some packages have a different name:

Import Package
cv2 opencv-python
sklearn scikit-learn
from google.cloud import storage google-cloud-storage

The full table is src/gpython/packages.json.

The install methods

Method Effect Available
uv pip install Installs into the environment only. No project file changes Always (pip if there is no uv)
uv add Writes to pyproject.toml and installs into the environment When the project has a pyproject.toml
  • ↑ / ↓ select the method. The selected row has a ●.
  • The title shows the exact command that enter runs.
  • gpython saves your selection as install_mode. The default is uv pip install.

Keys

Key Action
enter Install, then run the cell again
escape Do not install

After the prompt

  • If the installation fails, gpython shows the command, its exit code and the output of uv or pip. It shows them as a notification and below the cell.
  • A hint below the traceback keeps the :pip command. :pip without a name offers the same package.
  • If you run the cell again, gpython asks again.
  • If a module from the standard library is missing because Python was built without it, gpython tells you. It does not try to install it.

Install and do not ask

:set autoinstall installs the package and runs the cell again without a prompt. If an installation fails, gpython asks on the next run. :set noautoinstall brings the prompt back.

What gpython saves

Data Where
The environment that each notebook used last env: keys in the config file
The extras and groups of each uv project uv: keys in the config file
The install method install_mode in the config file

Clone this wiki locally