Adding ROOT C++ kernel to Jupyter Notebook container

Hi,
long story short: I have a dockerfile in which I install ROOT on the base image of a jupyter notebook.
After exporting the env variables, ROOT (JupyROOT 6.22/09) is importable on a python notebook.
The next step I want to achieve is to add the C++ kernel already present in $ROOTSYS/etc/notebook/kernels/root, and following the guide from @linev, I managed to have the C++ kernel selectable in the jupyter GUI options.
Here comes the issue: as soon as I open up a notebook with such a kernel, on the docker terminal I get this error:

[I 06:33:50.569 NotebookApp] Writing notebook-signing key to /home/jovyan/.local/share/jupyter/notebook_secret
[I 06:33:51.954 NotebookApp] Kernel started: a1cff1b3-409a-4d64-bebe-9097804bcf14, name: root
[W 06:33:52.038 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20210408063340 (172.17.0.1) 78.160000ms referer=http://127.0.0.1:8888/notebooks/Untitled.ipynb?kernel_name=root
Traceback (most recent call last):
  File "/installdir/lib/cppyy/__init__.py", line 60, in <module>
    importlib.import_module(libcppyy_mod_name)
  File "/opt/conda/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 556, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1101, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: libcppyy_backend3_8.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/opt/conda/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/installdir/lib/JupyROOT/__init__.py", line 1, in <module>
    from JupyROOT.helpers import cppcompleter, utils
  File "/installdir/lib/JupyROOT/helpers/cppcompleter.py", line 8, in <module>
    from JupyROOT.helpers import utils
  File "/installdir/lib/JupyROOT/helpers/utils.py", line 26, in <module>
    import ROOT
  File "/installdir/lib/ROOT/__init__.py", line 22, in <module>
    import cppyy
  File "/installdir/lib/cppyy/__init__.py", line 62, in <module>
    raise ImportError(
ImportError: Failed to import libcppyy3_8. Please check that ROOT has been built for Python 3.8
[I 06:33:54.952 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
Traceback (most recent call last):
  File "/installdir/lib/cppyy/__init__.py", line 60, in <module>
    importlib.import_module(libcppyy_mod_name)
  File "/opt/conda/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 556, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1101, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: libcppyy_backend3_8.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/opt/conda/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/installdir/lib/JupyROOT/__init__.py", line 1, in <module>
    from JupyROOT.helpers import cppcompleter, utils
  File "/installdir/lib/JupyROOT/helpers/cppcompleter.py", line 8, in <module>
    from JupyROOT.helpers import utils
  File "/installdir/lib/JupyROOT/helpers/utils.py", line 26, in <module>
    import ROOT
  File "/installdir/lib/ROOT/__init__.py", line 22, in <module>
    import cppyy
  File "/installdir/lib/cppyy/__init__.py", line 62, in <module>
    raise ImportError(
ImportError: Failed to import libcppyy3_8. Please check that ROOT has been built for Python 3.8

Do you have any suggestion on how to perform a debug here?

For the sake of clarity, here is the container: soap2g/root_notebook:cpp, I run it as

docker run -it --rm -e GRANT_SUDO=yes --user root -p 8888:8888 soap2g/root_notebook:cpp

ROOT Version: 6.22/09
Platform: Docker

Hi @Soap2G,

Welcome on the forum,

I hope, @etejedor can help you - once he is back from vacations.

Regards,
Sergey

1 Like

Hi,

This is an environment problem, you can try setting CPPYY_BACKEND_LIBRARY to the place where libcppyy_backend3_8.so is installed. But better than that, I would install ROOT with conda:

which would take care of these details.

Hi @etejedor, thanks a lot for the very useful insight. I did both, and I can confirm that both methods work.
I will definitely stick to the conda installation, since everything works fine.

Thanks again! :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.