Jupyter c++ with root

In the past I’ve always managed to get the c++ jupyter notebook working with root, compiled against python3 by pointing the PYTHON directory variables in cmake to the appropriate versions. Also, enabled PYTHON=ON, PYTHON3=ON, CLING=ON, CXX14=ON.

This time I did the same, I explicitly pointed cmake to the executable, library, and include variables to the python3.6 versions.

root notebook server starts normally, and I can open a python 2 notebook and python 3 notebook, but when
I try and open a c++ notebook it clearly is calling python 2:

/usr/bin/python: dynamic module does not define init function (initlibPyROOT)

Thanks.

ROOT Version: 6.12/06
Platform, compiler: Ubuntu 18.10, gcc7.2


Hi @spacestationspaz,

If you have both python2 and python3 installed in your computer, the ROOT kernel looks for “python”, which will be python2 by default.

Is there any possibility you can make python point to python3, so that the ROOT C++ kernel will pick the right one?

Sorry if I wasn’t clear before, but in cmake I set the following variables:

PYTHON_EXECUTABLE = /usr/bin/python3.6
PYTHON_INCLUDE_DIR = /usr/include/python3.6
PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython3.6m.so

I did try setting an alias for my user for python=python3, but that didn’t work. From what I read, setting such aliases or making symlinks system wide is ill-advised.

Thanks.

Hi @spacestationspaz,

Another thing you can do, if you did root --notebook, is to look in your home directory:

 ~/.rootnb/kernels/root/kernel.json

The ROOT kernel is by default trying to run with python. If you modify that file to use python3 instead, it should pick the right one without aliasing.

THANKS!!!
This fixed it. It was suggested in other root forums and other jupyter forums to modify the kernel.json file, but they told me to try the one either in the /usr/local/jupyter/kernels folder or in <root_install>/etc/notebook/kernels/root. No one mentioned there was a user version in the home folder!!!

To follow up, my original kernel.json file looked like this:

{
 "language": "c++",
 "display_name": "ROOT C++",
 "argv": [
  "python",
  "-m",
  "JupyROOT.kernel.rootkernel",
  "-f",
  "{connection_file}"
 ]
}

Changing line 4 to read “python3”, fixed it, like this:

{
 "language": "c++",
 "display_name": "ROOT C++",
 "argv": [
  "python3",
  "-m",
  "JupyROOT.kernel.rootkernel",
  "-f",
  "{connection_file}"
 ]
}

Some jupyter forums suggested pointing to the executable directly, but this turned out not to be necessary:

“/usr/bin/python3.6”,

Thanks again everyone.

https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292/2

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