Configuring-Jupyter-Kernels¶
python kernels are essentially very simple json files and some icons for the jupyter(lab) launcher. A kernel directory typically looks like this:
@max-display:~$ ls -1 /software/jupyter/share/kernels/pytorch/
kernel.json
logo-32x32.png
logo-64x64.png
logo-svg.svg
The kernel.json file
{
"argv": [
"/software/jupyter/.conda/envs/pytorch-1.13/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Pytorch",
"language": "python",
"metadata": {
"debugger": true
}
}
For python kernels there are only two relevant entries, the path to the python interpreter and the display_name. You can specify any location for the python interpreter, it doesn't have to be a conda environment, a private install of e.g. mambaforge or a classical virtual environment will also do, as long as ipykernel is part of the installation.
Kernel locations¶
jupyter will by default look for kernels in
- /software/mamba/2024.06/share/jupyter/kernels (and likewise for other conda/mamba installations)
- ~/.local/share/jupyter/kernels/
The search path can be extended to include arbitrary locations, for example max-jhub uses
- export JUPYTER_PATH="/software/jupyter/share:$JUPYTER_PATH"
This way jupyter will find kernels install in /software/jupyter/share/kernels
Whitelisting kernels¶
JupyterLab will by default show all kernels it finds in aforementioned locations. You can however hide all but explicitly specified (whitelisted) kernels.
Add to ~/.jupyter/jupyter_notebook_config.py for example
# only show kernels pytorch and julia
c.KernelSpecManager.whitelist = {'pytorch','julia'}
# also hide the default python3 kernel (which you usually don't want to do)
c.KernelSpecManager.ensure_native_kernel = False