ROOT import in python on macOS

Hi,
I installed ROOT 6.26 through Homebrew (brew install root) and it works fine. I later installed python with anaconda distribution and the version is 3.9.7, which also works fine with all the common python modules.

However, running the command import ROOT on python prompt gives the following error:

ModuleNotFoundError: No module named 'ROOT'

When I source /opt/homebrew/Cellar/root/6.26.02_1/bin/thisroot.sh and then try to import ROOT from python, I get the following error instead:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/root/6.26.02_1/lib/root/cppyy/__init__.py", line 60, in <module>
    importlib.import_module(libcppyy_mod_name)
  File "/Users/anita/anaconda3/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 565, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1173, in create_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
ImportError: dlopen(/opt/homebrew/Cellar/root/6.26.02_1/lib/root/libcppyy3_9.so, 0x0002): tried: '/opt/homebrew/Cellar/root/6.26.02_1/lib/root/libcppyy3_9.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/opt/homebrew/Cellar/root/6.26.02_1/lib/root/libcppyy3_9.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Cellar/root/6.26.02_1/lib/root/ROOT/__init__.py", line 22, in <module>
    import cppyy
  File "/opt/homebrew/Cellar/root/6.26.02_1/lib/root/cppyy/__init__.py", line 62, in <module>
    raise ImportError(
ImportError: Failed to import libcppyy3_9. Please check that ROOT has been built for Python 3.9

Any solution would be much appreciated.
Thanks,
Anita

Hello,

The problem seems to be that you are mixing the conda python with a homebrew ROOT. You can either use the system python (which should be compatible with the homebrew ROOT) or alternatively install ROOT with conda and use the conda Python. To install ROOT with conda, please see: