Import ROOT fails in Jupyter notebook

Hi.
I am trying to import ROOT in python3 (3.9.18) in a Jupyter notebook using VSCode.
My local machine is Mac, running on lxplus server.
I verified that root was compiled for this python version and that I can import ROOT from console.
When doing import ROOT from the notebook I get the following error.

{
	"name": "RuntimeError",
	"message": "property type mismatch or assignment not allowed",
	"stack": "---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In [3], line 1
----> 1 import ROOT
      2 import Garfield

File /usr/lib64/python3.9/site-packages/ROOT/__init__.py:70
     67 import sys
     68 from ._facade import ROOTFacade
---> 70 _root_facade = ROOTFacade(sys.modules[__name__], _is_ipython)
     71 sys.modules[__name__] = _root_facade
     73 # Configure meta-path finder for ROOT namespaces, following the Python
     74 # documentation and an example:
     75 #
     76 #   * https://docs.python.org/3/library/importlib.html#module-importlib.abc
     77 #
     78 #   * https://python.plainenglish.io/metapathfinders-or-how-to-change-python-import-behavior-a1cf3b5a13ec

File /usr/lib64/python3.9/site-packages/ROOT/_facade.py:95, in ROOTFacade.__init__(self, module, is_ipython)
     92 self.__loader__ = module.__loader__
     94 # Inject gROOT global
---> 95 self.gROOT = _gROOTWrapper(self)
     97 # Expose some functionality from CPyCppyy extension module
     98 self._cppyy_exports = [
     99     \"nullptr\",
    100     \"bind_object\",
   (...)
    106     \"SetOwnership\",
    107 ]

File /usr/lib64/python3.9/site-packages/ROOT/_facade.py:221, in ROOTFacade._finalSetup.<locals>.<lambda>(self, name, val)
    219 # Redirect lookups to cppyy's global namespace
    220 self.__class__.__getattr__ = self._fallback_getattr
--> 221 self.__class__.__setattr__ = lambda self, name, val: setattr(cppyy.gbl, name, val)
    223 # Register custom converters and executors
    224 self._register_converters_and_executors()

RuntimeError: property type mismatch or assignment not allowed"
}

Thank you for the help.
LM

_ROOT Version: 6.32.06
_Platform: Red Hat Enterprise Linux 9.4
_Compiler: g++ (GCC) 11.4.1 20231218
_Python: 3.9.18


Dear @mole.luca ,

Thanks for reaching out to the forum!

I have some trouble understanding your setup.

Jupyter notebook using VSCode.

So you are opening a jupyter notebook inside a VSCode instance on your machine.

My local machine is Mac, running on lxplus server.

Are you running VSCode, and most importantly the Jupyter server, on your machine? How does lxplus come into play here?

I verified that root was compiled for this python version and that I can import ROOT from console.

How did you verify this? In which console did you import ROOT?

Cheers,
Vincenzo

1 Like

Hi Vincenzo. Thank you for your prompt reply. Let me clarify.
I connect to lxplus through VSCode on my Mac.
The Jupyter notebook file is in lxplus, but I run it via VSCode (see attached screenshot).
In the lxplus terminal I can open python3 and import ROOT with no complaint.
Please let me know if further clarification is needed.
Thank you
Luca

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