Homebrew Installed Python 3.11 Can't Import Homebrew Installed ROOT

Hi, ROOT experts,

I’ve recently updated both ROOT and Python3 on my MacBook through Homebrew. But now I can’t use ROOT in Python and I got this when I tried to import ROOT:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/root/6.26.06_2/lib/root/cppyy/__init__.py", line 60, in <module>
    importlib.import_module(libcppyy_mod_name)
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'libcppyy3_11'

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.06_2/lib/root/ROOT/__init__.py", line 22, in <module>
    import cppyy
  File "/opt/homebrew/Cellar/root/6.26.06_2/lib/root/cppyy/__init__.py", line 62, in <module>
    raise ImportError(
ImportError: Failed to import libcppyy3_11. Please check that ROOT has been built for Python 3.11

ROOT Version: 6.26/06
Python Version: 3.11.2

Is there a good way to solve this problem?

Thank you!

Hi, @Wile_E_Coyote,

Thanks for your reply! I am having a hard time to degrade the Homebrew Python3 to the specific Python3 version that I get by using root-config --python3-version, do you know if there’s a good way to deal with this Homebrew Python version issue?

Thank you!

Never mind what I asked above, I’ve got it figured out. Thanks!

Hello, I’m interested in your solution, since I’m experiencing the same problem since python was upgraded by brew to 3.11. How did you solve? Python@3.10 is still installed on my system. Thanks!

Hi,
When you do python3 in the terminal, you call the newest Python you have; that is, Python 3.11, and this is not what you want because you can’t import ROOT in this version. So, you will do python3.10 in your terminal, then this specific version will be used. If you have a script, you may do this to execute it:
python3.10 script.py

Maybe you could define an: alias python=python3.10

Thanks to both, this is indeed what I’m currently doing:

alias python=“python3.10”
alias jupyterlab=“python3.10 -m jupyterlab”
alias jnotebook=“python3.10 -m notebook”

but I was hoping for a less patchy solution :wink:

Funnily enough pip3 does not need this hack if python@3.11 is not installed:

$ which pip3
/usr/local/opt/python@3.10/libexec/bin/pip3

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