Home | News | Documentation | Download

Cannot use ROOT in a Jupyter notebook

Hi !

I’ve installed Root on my computer and it works fine, so does Pyroot.
However, when I try to use jupyter notebook with root, it does not work.
I would really appreciate it if you could help me, please.

I’ve follow what is written here : HowTo_ROOT-Notebooks but when I enter the command “import ROOT” in jupyter notebook, it does not work.

The error message is : ImportError: Failed to import libcppyy3_8. Please check that ROOT has been built for Python 3.8

Here is the whole message :
ImportError Traceback (most recent call last)
C:\root\bin\cppyy_init_.py in
59 try:
—> 60 importlib.import_module(libcppyy_mod_name)
61 except ImportError:

~\anaconda3\new\lib\importlib_init_.py in import_module(name, package)
126 level += 1
→ 127 return _bootstrap._gcd_import(name[level:], package, level)

~\anaconda3\new\lib\importlib_bootstrap.py in _gcd_import(name, package, level)

~\anaconda3\new\lib\importlib_bootstrap.py in find_and_load(name, import)

~\anaconda3\new\lib\importlib_bootstrap.py in find_and_load_unlocked(name, import)

~\anaconda3\new\lib\importlib_bootstrap.py in _load_unlocked(spec)

~\anaconda3\new\lib\importlib_bootstrap.py in module_from_spec(spec)

~\anaconda3\new\lib\importlib_bootstrap_external.py in create_module(self, spec)

~\anaconda3\new\lib\importlib_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

ImportError: DLL load failed while importing libcppyy3_8: %1 n’est pas une application Win32 valide.

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)
----> 1 import ROOT

C:\root\bin\ROOT_init_.py in
20 environ[‘CPPYY_NO_ROOT_FILTER’] = ‘1’
—> 22 import cppyy
23 if not ‘ROOTSYS’ in environ:
24 # Revert setting made by cppyy

C:\root\bin\cppyy_init_.py in
60 importlib.import_module(libcppyy_mod_name)
61 except ImportError:
—> 62 raise ImportError(
63 ‘Failed to import {}. Please check that ROOT has been built for Python {}.{}’.format(
64 libcppyy_mod_name, major, minor))

ImportError: Failed to import libcppyy3_8. Please check that ROOT has been built for Python 3.8

Thank you very much for your help !


The problem seems to be that your Jupyter notebook is running with Python3.8, but the installation of ROOT that you are using has not been built for Python3.8.

Can you run the following commands to know with which version(s) your ROOT was built with?

root-config --python-version
root-config --python2-version
root-config --python3-version

Hi !

Thank you very much for your quick reply, I really appreciate it.

I cannot run the commands you’ve written, they are not recognized.

I suppose that it must be because I use Windows 10 professional edition, but the command you’ve told me about are for Linux users, isn’t it ?

I’m sorry but I’m a total newbie…

I’ve installed : Python version 3.8 for windows, the latest version of root, cmake, virtual studio (community version) + windows 10 SDK and anaconda for windows

Any advice, please ?

Thank you very much !

@bellenot can you give a hand here? Is there a command on Windows to know with what Python version ROOT was built?

Hi, the root-config script has been implemented after the 6.24 release, but FYI, the notebooks don’t work on Windows yet.
And ROOT 6.24/06 has been built with Python 3.9.6

So your best options are to use the Windows Subsystem for Linux (“WSL”) or a virtual machine or run the jupyter server on a Linux box and connect with a browser running on your windows box.

Hi everyone,

Thank you very much for your help.
So I will follow your advice Axel and install WSL.

I will post again if I need your assistance :slight_smile:

Thanks again for your kind attention.

Hi again,

So I’ve installed WSL with ubuntu.
First, when I tried to run jupyter notebook in ubuntu, I could not open jupyter note book (I got 500 error message : internal servor in my browser).
Then I ran the command pip install --upgrade nbconvert and I was able to run jupyter notebook.

I’m sorry in advance for my following newbies questions.

What I do not understand is : if I write “jupyter notebook” in Ubuntu, and copy paste the URL which appears there, I can access the jupyter page with my projects.
If I go in New, I can create a new notebook Python 3 (ipykernel) file.
But, if I run “import ROOT” and try to run the file, I still have the modulenotfounderror message.

So what I thought is, it seems like Root is not detected. So I tried to close/open ubuntu and enter the command source root/bin/thisroot.sh # also available: thisroot.{csh,fish,bat}

Because after I did it a few hours ago, when I went in new → I could not only create a new Python 3 (ipykernel) file, but also a C++/Root file or something like this (can’t remember the exact title).
So I told me, should Jupyroot work, it would make sense that Jupyroot should be used with C++/Root files in Jupyter Notebook, not with Python 3 (ipykernel) .

But maybe I’m completely wrong ?

Anyway, now I don’t have the possibility anymore, to create new “C++/Root files” in Jupyter notebook. This option disappeared, suddenly.
I can only create new Python 3 (ipykernel) files.

So again, I thought that maybe I should run again the command source root/bin/thisroot.sh # also available: thisroot.{csh,fish,bat}

but this command doesn’t work anymore, it says “-bash: root/bin/thisroot.sh: No such file or directory”

What I do not understand is : why doesn’t this command work anymore ?
Is there something else I should do ?

Thank you very much.
I hope that my questions are clear…


Can you run root --notebook and check if the C++ ROOT option appears again?

Note that in order to run that command you have to source thisroot.sh. I’m not completely sure why that file is not there anymore, in which directory did you install ROOT? Is it possible that you deleted it?

Hi etejedor,

Thanks for your help.

I’ve uninstalled and installed root again and the good news is that when I enter “root --notebook” in Ubuntu, the C++ ROOT option appears again.

However, I’m still not able to use root in Jupyter.
The error has changed, now when I write “import ROOT” it says

input_line_41:2:8: error: expect “;” after expression
import ROOT

So it seems that jupyter still does not detect root.

EDIT : Finally, it works !

I’m not sure to understand why , but the command “import ROOT” works with Python 3 (ipykernel) files, but not with ROOT C++ files.

Thanks again for your assistance.

Hi @sofia.r ,
that would be because import ROOT is a Python command and it is not valid C++ syntax. The “moral equivalent” in C++ is #include <...>, depending on what ROOT class you need to use.


Hi Enrico,

Thank you very much for your explanation :slight_smile: