# Failed to import ROOT in jupyter notebook in Scientific Linux 7

**URL:** <https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128>\
**Category:** ROOT\
**Tags:** jupyter\
**Created:** [November 15, 2023, 3:51pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128 "2023-11-15T15:51:16Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [November 15, 2023, 3:51pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/1 "2023-11-15T15:51:17Z")

</div>

Hi, I have the exact same problem as described in [this](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-docker-fedora-36/51517) 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

```sh
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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 15, 2023, 4:12pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/2 "2023-11-15T16:12:28Z")

</div>

Hi,

Can you start normal ROOT session and try:

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

```

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [November 15, 2023, 4:25pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/3 "2023-11-15T16:25:45Z")

</div>

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

```auto
$ 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] 

```

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 15, 2023, 4:27pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/4 "2023-11-15T16:27:45Z")

</div>

Means this should work.

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

---

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [November 15, 2023, 4:35pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/5 "2023-11-15T16:35:10Z")

</div>

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 ☹  
I checked in the notebook with:

```auto
%%bash
echo $PATH

```

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

---

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [November 15, 2023, 4:49pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/6 "2023-11-15T16:49:34Z")

</div>

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

```auto
$ 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> >{}
>>> 

```

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 15, 2023, 5:08pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/7 "2023-11-15T17:08:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [November 15, 2023, 7:27pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/8 "2023-11-15T19:27:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [November 20, 2023, 10:38pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/9 "2023-11-20T22:38:01Z")

</div>

Thank you for the many answers so far!

In the notebook:

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

```

returns

```sh
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:

```sh
$ /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)
{}
>>> 

```

---

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [November 20, 2023, 10:52pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/10 "2023-11-20T22:52:20Z")

</div>

As a temporary fix I modified

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

```

as

```py
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:

```py
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:

```auto
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

```auto
/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

```

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 21, 2023, 8:47am UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/11 "2023-11-21T08:47:48Z")

</div>

Hi,

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

From your cmake command:

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

```

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

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [November 21, 2023, 10:57am UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/12 "2023-11-21T10:57:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 21, 2023, 11:35am UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/13 "2023-11-21T11:35:02Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [November 21, 2023, 12:27pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/14 "2023-11-21T12:27:01Z")

</div>

Yes, sure. So like this?

```auto
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 

```

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 21, 2023, 12:28pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/15 "2023-11-21T12:28:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [December 4, 2023, 2:18am UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/16 "2023-12-04T02:18:27Z")

</div>

I did try this this weekend, i.e.

```auto
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:

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

```

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

```auto
%%bash
which root
echo $PATH
echo $PYTHONPATH

```

returns

```auto
/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

```auto
import ROOT

```

results in

```auto
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:

```auto
$ 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> >{}

```

☹

---

<div class="post-metadata">

**Author:** ![pmajor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pmajor](https://root-forum.cern.ch/u/pmajor)\
**Post date:** [December 4, 2023, 1:39pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/17 "2023-12-04T13:39:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [December 18, 2023, 1:39pm UTC](https://root-forum.cern.ch/t/failed-to-import-root-in-jupyter-notebook-in-scientific-linux-7/57128/18 "2023-12-18T13:39:53Z")

</div>

Closed on December 18, 2023, 1:39pm UTC

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