Ctrl K

Register Jupyter Kernels

Register and list Jupyter kernels using venv

In this case we assume no jupyter is availble in the global environment, instead we will use the venv to install the jupyter and manage the operations after venv activation.

Register a venv as a kernel

Typical pattern with a project-local venv:

cd /home/$USER/projects/my_ml_project
source .venv/bin/activate
pip install ipykernel
python -m ipykernel install --user --name=my_ml_project

List kernels

jupyter kernelspec list          # names + paths
jupyter kernelspec list --json   # full details including argv

Inspect a kernel's Python

Each kernel stores its Python path as an absolute path in kernel.json. Read it to verify which interpreter the kernel actually launches.

cat ~/.local/share/jupyter/kernels/finlab-backend/kernel.json

The argv field is the launch command:

"argv": [
  "/full/path/to/project/.venv/bin/python",
  "-Xfrozen_modules=off",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
]

Check whether that Python still exists:

ls -l "/full/path/to/project/.venv/bin/python"

# or as a boolean check
test -x "/full/path/to/project/.venv/bin/python" && echo "exists" || echo "missing"

Fix a kernel

A kernel will be no longer availble if its registered Python path no longer available in case like after renaming a project folder or recreating a venv. The fix is to uninstall and register again from the new location, keeping the same --name so existing notebooks that reference the kernel keep working.

jupyter kernelspec uninstall old-kernel-name

cd /path/to/current/project
source .venv/bin/activate
pip install ipykernel
python -m ipykernel install --user --name=old-kernel-name