Failed to import ROOT in jupyter notebook in Scientific Linux 7

Hi, I have the exact same problem as described in this post, except I use Scientific Linux 7 and I compiled ROOT 6.28.6 from source for our computer with G++ (GCC) 11.2.0 and

cmake -DCMAKE_INSTALL_PREFIX="/cern_root_6.28.6_cpp17" -DCMAKE_C_COMPILER=/usr/local/bin/gcc -DCMAKE_CXX_COMPILER=/usr/local/bin/g++ -DCMAKE_LINKER=/usr/local/bin/g++ -DCMAKE_CXX_STANDARD=17 -DPython3_EXECUTABLE=$(which python3) -DPython2_EXECUTABLE=$(which python2) ../root-6.28.06 
sudo cmake --build . -j16 --target install

The problem is, that I don’t really understand what the answer means in my case. What can I do to make this work?

Thanks in advance!
( @eguiraud perhaps?)

The exact traceback is this:

Welcome to JupyROOT 6.28/06
Error in callback <bound method CaptureDrawnPrimitives._post_execute of <JupyROOT.helpers.utils.CaptureDrawnPrimitives object at 0x7f01c49e85c0>> (for post_execute):
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/cern_root_6.28.6_cpp17/lib/JupyROOT/helpers/utils.py in _post_execute(self)
    456 
    457     def _post_execute(self):
--> 458         NotebookDraw()
    459 
    460     def register(self):

/cern_root_6.28.6_cpp17/lib/JupyROOT/helpers/utils.py in NotebookDraw()
    446     DrawGeometry()
    447     DrawCanvases()
--> 448     DrawRCanvases()
    449 
    450 class CaptureDrawnPrimitives(object):

/cern_root_6.28.6_cpp17/lib/JupyROOT/helpers/utils.py in DrawRCanvases()
    439 
    440 def DrawRCanvases():
--> 441     rdrawers = GetRCanvasDrawers()
    442     for drawer in rdrawers:
    443         drawer.Draw()

/cern_root_6.28.6_cpp17/lib/JupyROOT/helpers/utils.py in GetRCanvasDrawers()
    411 def GetRCanvasDrawers():
    412     if not RCanvasAvailable(): return []
--> 413     lOfC = ROOT.Experimental.RCanvas.GetCanvases()
    414     return [NotebookDrawer(can.__smartptr__().get()) for can in lOfC if can.IsShown()]
    415 

ValueError: static const vector<shared_ptr<ROOT::Experimental::RCanvas> > ROOT::Experimental::RCanvas::GetCanvases() =>
    ValueError: nullptr result where temporary expected

Hi,

Can you start normal ROOT session and try:

root [0] auto lst = ROOT::Experimental::RCanvas::GetCanvases()

Regards,
Sergey

Thank you for the reply Sergey. This is my output:

$ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/06                        https://root.cern |
  | (c) 1995-2023, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Aug 28 2023, 11:29:15                 |
  | From tags/v6-28-06@v6-28-06                                      |
  | With g++ (GCC) 11.2.0                                            |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] auto lst = ROOT::Experimental::RCanvas::GetCanvases()
(std::vector<std::shared_ptr<ROOT::Experimental::RCanvas>, std::allocator<std::shared_ptr<ROOT::Experimental::RCanvas> > > &) {}
root [1] 

Means this should work.

Do you have in $PATH some other ROOT installations?
Do you have system-wide ROOT installed?

I have no system-wide installations, but I have older versions on the computer, yes. We change the versions by sourcing the appropriate thisroot.sh
According to the error python picks up the proper version in the notebook too :frowning:
I checked in the notebook with:

%%bash
echo $PATH

and the correct one appears to be the only root directory in the $PATH.

Calling the test above in a simple python terminal also works:

$ python3
Python 3.6.8 (default, Nov  9 2023, 05:22:21) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> ROOT.Experimental.RCanvas.GetCanvases()
vector<shared_ptr<ROOT::Experimental::RCanvas> >{}
>>> 

I am not python expert, but may be python3.6 is too old? @eguiraud @vpadulan?

Currently we support all versions of Python 3, so that should not be the direct cause for the problem seen by the user. The next thing I would try is to make sure that the Python executable used in the ROOT installation is the same Python executable that launches the jupyter notebook.

Cheers,
Vincenzo

Thank you for the many answers so far!

In the notebook:

import sys
print(sys.version)
print(sys.executable)

returns

3.6.8 (default, Nov  9 2023, 05:22:21) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
/usr/bin/python3

importing ROOT still meets the same show-stopper error.

In my terminal calling this python:

$ /usr/bin/python3
Python 3.6.8 (default, Nov  9 2023, 05:22:21) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> lOfC = ROOT.Experimental.RCanvas.GetCanvases()
>>> print(lOfC)
{}
>>> 

As a temporary fix I modified

/cern_root_6.28.6_cpp17/lib/JupyROOT/helpers/utils.py

as

def GetRCanvasDrawers():
    return []

The module now imports and I can read root files and operate on histograms, which was the most important part of the whole thing for me.
However, when I try to do a plot with ROOT the script that works in the interactive python shell gives an error. Maybe this hints at something? The simple script:

h = ROOT.TH1F("gauss","Example histogram",100,-4,4)
h.FillRandom("gaus")
c = ROOT.TCanvas("myCanvasName","The Canvas Title",800,600)
h.Draw()
c.Draw()

The error I am getting in the notebook is:

IncrementalExecutor::executeFunction: symbol '_ZN5cling7runtime6gClingE' unresolved while linking [cling interface function]!
You are probably missing the definition of cling::runtime::gCling
Maybe you need to load the corresponding shared library?
Error in <TH1F::FillRandom>: Unknown function: gaus
IncrementalExecutor::executeFunction: symbol '_ZN5cling7runtime6gClingE' unresolved while linking [cling interface function]!
You are probably missing the definition of cling::runtime::gCling
Maybe you need to load the corresponding shared library?

If in the notebook I echo my path I get

/usr/bin:/home/pmajor/.local/bin:/home/pmajor/.vscode-server/bin/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e/bin/remote-cli:/cern_root_6.28.6_cpp17/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/pmajor/.local/bin:/home/pmajor/bin:/home/pmajor/.local/bin:/home/pmajor/bin:/home/pmajor/.vscode-server/bin/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e/bin/remote-cli:/cern_root_6.28.6_cpp17/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/pmajor/.local/bin:/home/pmajor/bin:/home/pmajor/.local/bin:/home/pmajor/bin

Hi,

You trying to fix symptoms, but not the problem itself.
Something wrong with jupyter and pyROOT.

From your cmake command:

sudo cmake --build . -j16 --target install

Are you really install ROOT libraries in system directories?
Can you try without installing it?

Regards,
Sergey

I dont think anything goes into the system directories. I have -DCMAKE_INSTALL_PREFIX="/cern_root_6.28.6_cpp17" so install should just copy the build results here, right?

Can you try without install prefix and without --install command?

Just to be sure that this is not kind of broken configuration of jupyter.

Yes, sure. So like this?

cmake -DCMAKE_C_COMPILER=/usr/local/bin/gcc -DCMAKE_CXX_COMPILER=/usr/local/bin/g++ -DCMAKE_LINKER=/usr/local/bin/g++ -DCMAKE_CXX_STANDARD=17 -DPython3_EXECUTABLE=$(which python3) -DPython2_EXECUTABLE=$(which python2) ../root-6.28.06 
sudo cmake --build . -j16 

Yes, try such configuration.
And do not use sudo.

I did try this this weekend, i.e.

cmake -DCMAKE_C_COMPILER=/usr/local/bin/gcc -DCMAKE_CXX_COMPILER=/usr/local/bin/g++ -DCMAKE_LINKER=/usr/local/bin/g++ -DCMAKE_CXX_STANDARD=17 -DPython3_EXECUTABLE=$(which python3) -DPython2_EXECUTABLE=$(which python2) ../root-6.28.06 
cmake --build . -j16

and I changed the env variables globally by modifying my selector file: /etc/profile.d/selectroot.sh:

. /home/pmajor/install_new_root/build_dir/bin/thisroot.sh

and the result is the same. In the VS Code ipynb:

%%bash
which root
echo $PATH
echo $PYTHONPATH

returns

/home/pmajor/install_new_root/build_dir/bin/root
/usr/bin:/home/pmajor/.local/bin:/home/pmajor/.vscode-server/bin/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e/bin/remote-cli:/home/pmajor/install_new_root/build_dir/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/pmajor/.local/bin:/home/pmajor/bin:/home/pmajor/.local/bin:/home/pmajor/bin:/home/pmajor/.vscode-server/bin/1a5daa3a0231a0fbba4f14db7ec463cf99d7768e/bin/remote-cli:/home/pmajor/install_new_root/build_dir/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/pmajor/.local/bin:/home/pmajor/bin:/home/pmajor/.local/bin:/home/pmajor/bin
/home/pmajor/install_new_root/build_dir/lib:/home/pmajor/install_new_root/build_dir/lib

and

import ROOT

results in

Welcome to JupyROOT 6.28/06
Error in callback <bound method CaptureDrawnPrimitives._post_execute of <JupyROOT.helpers.utils.CaptureDrawnPrimitives object at 0x7ff0922f0358>> (for post_execute):
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/install_new_root/build_dir/lib/JupyROOT/helpers/utils.py in _post_execute(self)
    456 
    457     def _post_execute(self):
--> 458         NotebookDraw()
    459 
    460     def register(self):

~/install_new_root/build_dir/lib/JupyROOT/helpers/utils.py in NotebookDraw()
    446     DrawGeometry()
    447     DrawCanvases()
--> 448     DrawRCanvases()
    449 
    450 class CaptureDrawnPrimitives(object):

~/install_new_root/build_dir/lib/JupyROOT/helpers/utils.py in DrawRCanvases()
    439 
    440 def DrawRCanvases():
--> 441     rdrawers = GetRCanvasDrawers()
    442     for drawer in rdrawers:
    443         drawer.Draw()

~/install_new_root/build_dir/lib/JupyROOT/helpers/utils.py in GetRCanvasDrawers()
    411 def GetRCanvasDrawers():
    412     if not RCanvasAvailable(): return []
--> 413     lOfC = ROOT.Experimental.RCanvas.GetCanvases()
    414     return [NotebookDrawer(can.__smartptr__().get()) for can in lOfC if can.IsShown()]
    415 

ValueError: static const vector<shared_ptr<ROOT::Experimental::RCanvas> > ROOT::Experimental::RCanvas::GetCanvases() =>
    ValueError: nullptr result where temporary expected

While in my terminal:

$ which root
~/install_new_root/build_dir/bin/root
$ echo $PATH
/home/pmajor/install_new_root/build_dir/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/pmajor/.local/bin:/home/pmajor/bin
$ echo $PYTHONPATH
/home/pmajor/install_new_root/build_dir/lib
$ python3
Python 3.6.8 (default, Nov  9 2023, 05:22:21) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> ROOT.Experimental.RCanvas.GetCanvases()
vector<shared_ptr<ROOT::Experimental::RCanvas> >{}

:frowning:

Ok, I compiled python 3.10 for our machine, which was not exactly a walk in the park and built root against that. Now it seems to work. I ll keep testing and will let you know if sg is not right.

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