Skip to content

Using the ROOT framework in notebooks

The workers in the NAF have ROOT installed for python version 3.9

  • rpm package python3-root for the python ROOT package
  • rpm package python3-jupyroot for the Jupyter kernel for ROOT

The Jupyterhub itself runs on python version 3.12 and the corresponding rpm packages are not yet available for ROOT.

You have two options and in either case you need to install two packages locally.

Local installation of the metakernel and jupyter packages

These are not available as rpm packaged version for some reason.

They therefore should be installed locally as needed, as mixing pip and rpm based python packages on system level is not recommended.

But you can easily install into your AFS them from a terminal started from a server:

pip -V
pip install --user jupyter metakernel

Make sure you use the pip version for Python 3.9, hence the pip -V.

It apparently can happen that the terminal environment gets mixed up for some reason, which can result in errors like

% pip -V
The folder you are executing pip from can no longer be found

In this case you should restart the terminal with a fresh environment, which requires a restart of the server.

See also stackoverflow.

Option 1: use the installed Jupyter kernel for ROOT

The ROOT kernel for jupyter can run C++ code (default) or python code from cells.

When you "Change Kernel" from the menu, you should find the kernel "Root C++ (Python 3)" among the options.

With this kernel, you can explicitly select the language by prefixing the cell with %%cpp and %%python, respectively.

Example screenshot

Option 2: use a custom python 3.9 kernel

The other option, if you don't need the C++ capabilities, is to use a plain python kernel.

First create a directory

~/.local/share/jupyter/kernels/some-name-for-your-kernel

Within this directory create a file named kernel.json with the following content:

{
 "language": "python",
 "display_name": "Python3.9",
 "argv": [
  "/usr/bin/python3.9",
  "-m",
  "ipykernel_launcher",
  "-f",
     "{connection_file}"
 ]
}

Assuming the metakernel and jupyter packages are available, you should be able to now switch to this kernel.

It should show as "Python3.9" (per display_name).

documentation at root.cern