Problem running pyroot on freshly installed ROOT with brew

Hello

I have installed root on my mac with brew - so far so good and I can open root and see that root v.32.06 is installed. However, when trying to execute a pyroot code, I get this

python3 -c "import ROOT; print(ROOT.__version__)" Traceback (most recent call last): File "<string>", line 1, in <module> import ROOT; print(ROOT.__version__) ^^^^^^^^^^^ File "/opt/homebrew/Cellar/root/6.32.06/lib/root/ROOT/__init__.py", line 25, in <module> import cppyy File "/opt/homebrew/Cellar/root/6.32.06/lib/root/cppyy/__init__.py", line 81, in <module> from ._cpython_cppyy import * File "/opt/homebrew/Cellar/root/6.32.06/lib/root/cppyy/_cpython_cppyy.py", line 22, in <module> import libcppyy as _backend ImportError: dlopen(/opt/homebrew/Cellar/root/6.32.06/lib/root/libcppyy.so, 0x0002): symbol not found in flat namespace '__Py_HashPointer'

Any ideas how to fix it?

Thanks
Alex

Sorry to hear to encounter such a problem.

That’s with v6.32, right ?
Which version of MacOS do you have ? And which Command Line Tools ?
You can find out the CTL version using:

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables          

I am in Sonoma 14.6.1 (I guess that is the latest update)

executing your command, I get

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables package-id: com.apple.pkg.CLTools_Executables version: 15.3.0.0.1.1708646388 volume: / location: / install-time: 1714509224

just to note - I can open Root and TBrowser for example, but I cannot execute any pyroot code.

Thanks

Ok, so that’s not with sequoia (MacOS 15). I this problem new ? What has changed since last time it worked ?

I am not sure I follow :wink: I indeed did update to MacOs 16, but I dont remember any problems in the past. So, I gather this is a new problem…

MacOS 16 does not exist yet, the latest is 15.
May be your Python is not up to date ?

sorry :wink: yes, I am in Sonoma 14.6.1 as said.

I did uninstall, did a brew update etc and reinstall root but the problem is still there

Ok. May be installing from source ?

git clone https://github.com/root-project/root.git root
mkdir root-build
cd root-build
cmake ../root
make -j8
source bin/thisroot.sh
root --web=off

while compiling unfortunatelly, I get into errors…

Built target MetaCling While building module 'Core': While building module 'Darwin' imported from /Users/alkaloge/root-build/include/TSystem.h:27: In file included from <module-includes>:358: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/curses.h:2918: /opt/local/include/unctrl.h:61:54: error: conflicting types for 'unctrl' NCURSES_EXPORT(NCURSES_CONST char *) NCURSES_SP_NAME(unctrl) (SCREEN*, chtype); ^ /opt/local/include/unctrl.h:58:38: note: previous declaration is here NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype); ^ While building module 'Core': While building module 'Darwin' imported from /Users/alkaloge/root-build/include/TSystem.h:27: In file included from <module-includes>:362: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/form.h:39: /opt/local/include/curses.h:684:45: error: functions that differ only in their return type cannot be overloaded extern NCURSES_EXPORT(NCURSES_CONST char *) keyname (int); /* implemented */ ...

That’s weird. Compilation should work. You did exactly what I proposed ? You started from a clean root-build folder ? it looks like the errors come from Xcode include. Is there any XCode update available on you machine ?

yes, clean dir etc - and no, there are no XCode updates available…

May be an answer here:

no, unfortunately this does not work for me…

As it seems to be a python issue may be our python experts @vpadulan and @jonas may have an idea about it ?

Dear @Alkass ,

A google search for your symbol not found in flat namespace '__Py_HashPointer' issue led me to python - What does "Symbol not found / Expected in: flat namespace" actually mean? - Stack Overflow which suggests there is some mismatch in your compiler toolchain on your system, similarly to the other forum post that was linked above.

I am able to reproduce the same issue on my MacOS 15 machine, so I opened a github issue on the homebrew core repository `brew install root` missing CPython symbol · Issue #195193 · Homebrew/homebrew-core · GitHub .

Best,
Vincenzo

1 Like

Dear @Alkass ,

The homebrew team was very fast in their reply. As you can read from the link provided above, apparently the packages is built with Python 3.12, so that Python version must be used when using ROOT from Python. I will ask the homebrew team if this is something that can be embedded in the formula so that this type of mismatch does not happen again in the future.

Cheers,
Vincenzo

1 Like

And just for reference, if I follow the homebrew dev’s suggestion and I use python3.12 (installed via brew install python@3.12) on my machine, then ROOT works

python3.12
Python 3.12.7 (main, Oct  1 2024, 02:05:46) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>
1 Like

Can you clarify if you then use precompiled root version or maybe you build it on your machine?

thanks
-a

Dear @Alkass ,

I just ran brew install root, then used python@3.12 from homebrew, and it worked.

Cheers,
Vincenzo

Damn…The problem seems to still be there for me - I installed root with brew, then when trying to run my pyroot

> python3 Fit.py
Traceback (most recent call last): File "/Users/alkaloge/Paper/METPaper/AN-21-167/Fit.py", line 1, in <module> import ROOT File "/opt/homebrew/Cellar/root/6.32.06/lib/root/ROOT/__init__.py", line 25, in <module> import cppyy File "/opt/homebrew/Cellar/root/6.32.06/lib/root/cppyy/__init__.py", line 81, in <module> from ._cpython_cppyy import * File "/opt/homebrew/Cellar/root/6.32.06/lib/root/cppyy/_cpython_cppyy.py", line 22, in <module> import libcppyy as _backend ImportError: dlopen(/opt/homebrew/Cellar/root/6.32.06/lib/root/libcppyy.so, 0x0002): symbol not found in flat namespace '__Py_HashPointer'

although I now have the right python version
python3 --version Python 3.13.0

I also trying to donwnload and compile, but compilation fails…