Segfault when importing ROOT in python

I just installed ROOT but I can’t import it into python without a segfault error. I am on MacOs 10.15 and am using python 3.7.3. I installed root by activating the virtual environment I will be using and then the following:

wget https://root.cern.ch/download/root_v6.16.00.source.tar.gz
tar -zxf root_v6.16.00.source.tar.gz
mkdir root-6.16.00_builddir
cd root-6.16.00_builddir
cmake …/root-6.16.00
cmake --build .
source bin/thisroot.sh
python -m pip install root_numpy

I am able to open root in terminal without error, but I get a segfault if I open python in terminal and try to import ROOT. It might be worth noting that when I did ‘cmake …/root-6.16.00,’ I got some error messages saying that certain things like PCRE, GIF, PNG, JPEG, and a lot more could not be found. Then it also said that certain tests failed, but I was still able to do the next step and open root later so I wasn’t sure if it was an issue.

Has anyone had a similar problem or have some advice for how to fix this? (Sorry if anything is unclear I am not great with this stuff)

What does the segfault say? I would get a segfault when I try to load ROOT into a python interpreter with a different version then the python version which I built ROOT against. This can happen if you have multiple python installation on your machine.

Is there a reason why you need specifically version 6.16? There are a couple more recent version available from https://root.cern/downloading-root that you can use directly (no need for cmake).

Below is the full error message. I don’t think there’s any reason why I need to use that specific version, I just used the exact same commands that my professor said he used and I wasn’t sure how to do it otherwise. I don’t think the interpreter version is the issue because that did happen before I installed ROOT but I fixed it first. Is there a better way I should use to download it?

*** Break *** segmentation violation

[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)

[/usr/lib/system/libsystem_malloc.dylib] szone_size (no debug info)

[/Users/Trevor/anaconda3/lib/libpython3.7m.dylib] PyUnicode_InternFromString (no debug info)

[/Users/Trevor/root-6.16.00_builddir/lib/libPyROOT.so] PyROOT::CreatePyStrings() /Users/Trevor/root-6.16.00/bindings/pyroot/src/PyStrings.cxx:64

[/Users/Trevor/root-6.16.00_builddir/lib/libPyROOT.so] PyInit_libPyROOT /Users/Trevor/root-6.16.00/bindings/pyroot/src/RootModule.cxx:848

[/Users/Trevor/anaconda3/bin/python] _PyImport_LoadDynamicModuleWithSpec (no debug info)

[/Users/Trevor/anaconda3/bin/python] _imp_create_dynamic (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyMethodDef_RawFastCallDict (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyCFunction_Call (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyFunction_FastCallKeywords (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] object_vacall (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyImport_ImportModuleLevelObject (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] builtin_exec (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyMethodDef_RawFastCallDict (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyCFunction_Call (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyFunction_FastCallKeywords (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] object_vacall (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyImport_ImportModuleLevelObject (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] builtin_exec (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyMethodDef_RawFastCallDict (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyCFunction_Call (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyFunction_FastCallKeywords (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function_code_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] object_vacall (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyImport_ImportModuleLevelObject (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyRun_InteractiveOneObjectEx (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyRun_InteractiveLoopFlags (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyRun_AnyFileExFlags (no debug info)

[/Users/Trevor/anaconda3/bin/python] pymain_main (no debug info)

[/Users/Trevor/anaconda3/bin/python] main (no debug info)

[/usr/lib/system/libdyld.dylib] start (no debug info)

[] (no debug info)

Here is the compilation guide, with a link to prerequisites:
https://root.cern/building-root
Even if you get an already compiled binary version (from the link ahesam gave you), it won’t hurt to install the prerequisites.
If you go for the binaries, just get the latest Pro release binary for your OS and clang. Note that those binaries were compiled for some Python version (if it was python2.xx it won’t work with python 3.xx); I don’t use MacOS, so I don’t know the version used to generate the binaries (for Ubuntu 18.04, for instance, it is compiled with python2, so the root binary doesn’t work with python3); if the binary doesn’t work you will need to compile your own.

You can also check what version of python ROOT is built with using root-config --python-version after you sourced thisroot.sh (found in <root_install_path>/bin). Check if it’s the same version as the python you are trying to import ROOT in (which you say is 3.7.3).

When I do “root-config --python-version” nothing seems to print. I am not sure why because if I type “root-config --has-python” I get a yes.

I also tried using the binary installation instead. Now when I try to import ROOT in python I get this error “ImportError: dynamic module does not define module export function (PyInit_libPyROOT)”

I think the issue is the python version. It says ROOT was built with 2.7.16 but I definitely need python3 so I don’t think the binaries are an option.

See https://sft.its.cern.ch/jira/browse/ROOT-10167. You need to update to one of the fixed versions at least.

BTW, if you are installing on Mac OS, I recommend installing from our binary releases, or from a package manager like Homebrew. See https://formulae.brew.sh/formula/root for more information.
If you use anaconda, you should probably try to install root from conda-forge rather than compile it yourself.

I tried installing via homebrew but gave up and cut it short after it had been working on it for more than 24 hours. Is there something I could do to see a progress bar when installing with homebrew? It spent 24 hours without giving any indications after printing this:
==> Installing root
Warning: Building root from source:
The bottle hardcodes locations inside Xcode.app
=> cmake … -DCLING_CXX_PATH=clang++ -DCMAKE_INSTALL_ELISPDIR=/usr/local/Cellar/root/6.20.04_2/share/emacs/site-lisp/root -DPYTHON_EXECUTABLE=/
==> make install

I also just tried with anaconda instead and it installed pretty quickly but I get an error when importing ROOT. I checked and I get 3.8.2 for python --version and for root-config --python-version. This is the error I get:

Traceback (most recent call last):
File “”, line 1, in
File “/Users/Trevor/anaconda3/envs/myenv/lib/python3.8/site-packages/ROOT.py”, line 24, in
import cppyy
File “/Users/Trevor/anaconda3/envs/myenv/lib/python3.8/site-packages/cppyy.py”, line 61, in
import libPyROOT as _backend
ImportError: dlopen(/Users/Trevor/anaconda3/envs/myenv/lib/python3.8/site-packages/libPyROOT.so, 2): Library not loaded: @rpath/libzstd.1.3.7.dylib
Referenced from: /Users/Trevor/anaconda3/envs/myenv/lib/libCore.6.20.04.so
Reason: image not found