PyROOT when importing ROOT in Jupiter notebook within VSCode

Hi everyone,
I am having issues when importing PyROOT within a Jupiter notebook opened in Visual Studio Code. The stack trace is the following:

RuntimeError                              Traceback (most recent call last)
/var/folders/rc/xzc2ckrd3v36016q3zr884vc0000gr/T/ipykernel_33363/3488689890.py in <module>
      1 import numpy as np
----> 2 import ROOT
      3 from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,AutoMinorLocator)

~/root-6.24.02-install/lib/ROOT/__init__.py in <module>
     20 environ['CPPYY_NO_ROOT_FILTER'] = '1'
     21 
---> 22 import cppyy
     23 if not 'ROOTSYS' in environ:
     24     # Revert setting made by cppyy

~/root-6.24.02-install/lib/cppyy/__init__.py in <module>
    129     from ._pypy_cppyy import *
    130 else:
--> 131     from ._cpython_cppyy import *
    132 if clean_cbl:
    133     del os.environ['CPPYY_BACKEND_LIBRARY'] # we set it, so clean it

~/root-6.24.02-install/lib/cppyy/_cpython_cppyy.py in <module>
     16 # first load the dependency libraries of the backend, then pull in the
     17 # libcppyy extension module
---> 18 c = loader.load_cpp_backend()
...
---> 74         raise RuntimeError("could not load cppyy_backend library")
     75 
     76     return c

RuntimeError: could not load cppyy_backend library

If I open Jupiter notebook on the internet, PyROOT is correctly working, while it doesn’t when opened within Visual Studio. Is someone able to help me ?

Thank you in advance

ROOT Version: 6.24.02
Platform: Mac OS Big Sur 11.6.4
Compiler: g++


I am not sure to fully understand what you are doing. You try to open a notebook in visual VScode ? Is it possible @vpadulan ? It seems you run on Mac…
“IOS BigSur” … I guess MacOS ? IOS is for IPhones…

Hi @Maria_Adriana_Sabia ,
I would like to ask you for a few more details so that I can better understand the problem.

  1. How did you install ROOT?
  2. How do you source the correct Python environment in your Visual Studio Code session? i.e. do you make sure that import ROOT works if you type it in the Visual Studio Code terminal for example?

Cheers,
Vincenzo

Hi! I think I have solved my problem. VSCode jupyter notebook doesn’t run bashrc by default before starting, so it simply did not source my env variables, including the ROOT related ones. I solved by running VSCode from a directory in which I sourced thisroot.sh

1 Like

Hi @Maria_Adriana_Sabia ,
Ok perfect! The jupyter notebook in VS code also has an option box on the top right to select the Python kernel you want to run the notebook with. It might be enough to select the correct Python executable that you know will be able to import ROOT. As a quick test, I created a new Python environment with conda create -c conda-forge --name root624 root==6.24, then I could select the kernel in VS code with the name root624 and it worked right away. Here I tried with ROOT 6.24 just because that’s the version you used in your initial post, if you can update to the latest version always do so.
Cheers,
Vincenzo

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