Failed to import libcppyy3_10. Please check that ROOT has been built for Python 3.10

Trying to use ROOT in Python. Downloaded ROOT via macports. Following error when I try to import ROOT:

~/repos$ python 
>>> import ROOT
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cppyy/__init__.py", line 60, in <module>
    importlib.import_module(libcppyy_mod_name)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 674, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1176, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/libcppyy3_10.so, 0x0002): Library not loaded: @rpath/libcppyy_backend3_10.6.26.so
  Referenced from: /opt/local/libexec/root6/lib/root/libcppyy3_10.6.26.00.so
  Reason: tried: '/Users/stuartwalker/repos/bdsim/install/bin/../lib/libcppyy_backend3_10.6.26.so' (no such file), '/opt/local/libexec/root6/lib/root/../lib/root/libcppyy_backend3_10.6.26.so' (no such file), '/opt/local/libexec/root6/lib/root/../lib/root/libcppyy_backend3_10.6.26.so' (no such file), '/usr/local/lib/libcppyy_backend3_10.6.26.so' (no such file), '/usr/lib/libcppyy_backend3_10.6.26.so' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ROOT/__init__.py", line 22, in <module>
    import cppyy
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cppyy/__init__.py", line 62, in <module>
    raise ImportError(
ImportError: Failed to import libcppyy3_10. Please check that ROOT has been built for Python 3.10

Just for sanity, I checked the versions and yes they match:

~/repos$ python --version
Python 3.10.2

and

~/repos$ root-config --python3-version
3.10.2

So the versions definitely match. What is there to be done?

ROOT still doesn’t really work on arm it seems. It is still not possible to compile ROOT from source on arm mac (due to error in compiling the bundled freetype, why can’t I use my own builtin freetype btw? Why must I use the packaged one?). The .pkg doesn’t produce any runnable binaries (no idea why). ROOT from conda also crashes. So nothing works. I think macports is my best bet. But I need pyROOT. Any tips? What is going on?

Please help me. Thank you for your time.

ROOT Version: 6.26/00
Platform: macosxarm64 / macOS Monterey (12.1)
Compiler: used macports precompiled binary


OK what I did to fix it,

sudo install_name_tool -rpath "@loader_path/../lib/root" "@loader_path/../../lib/root"  /opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/libcppyy3_10.6.26.so
sudo install_name_tool -rpath "@loader_path/../lib/root" "@loader_path/../../lib/root"  /opt/local/libexec/root6/lib/root/libROOTPythonizations3_10.6.26.00.so
sudo install_name_tool -rpath "@loader_path/../lib/root" "@loader_path/../../lib/root"  /opt/local/libexec/root6/lib/root/libRIO.6.26.00.so

So @loader_path/../lib/root should have been @loader_path/../../lib/root to get the lookup to work correctly. I don’t know why this path is set incorrectly.

Maybe you added -Dgnuinstall=ON to your configuration? How did you install ROOT?

I installed ROOT via macports. Installing from source is not an option due to other mystery compile time errors (regarding freetype, libAfterImage, and arm). The port file is here:

It looks like Dgnuinstall=ON is on, yes (line 108). What does this mean?

The option gnuinstall makes libraries be installed into lib/root rather than just lib. Unfortunately, the code that sets the RPATH on Mac only works if gnuinstall=OFF. Please file this as a bug. To explain a bit further here, the problem is that although the bin to libdir works for, e.g. root.exe, in Python, it’s another library that is trying to load, so the relative path from .../bin to .../root/lib doesn’t work, as the file starting the search is also in .../root/lib and not in .../bin, so using ../root/lib doesn’t work as a relative path. Does root.exe work after you modify the RPATH with install_name_tool?

OK thanks, I think I understand. I will file bug report for ROOT.

Yes root.exe still works even after changing the rpath.

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