Seg Fault when importing Root in python

I am aware that this is a frequent issue which has been posted about before but I have yet to find a solution on this forum.

I am currently running Mac OS X 10.15.5 (Catalina) and have installed python via Pyenv which I have installed with Homebrew.

I am running Python 3.8.0 and it is the default python on my machine (“which python” returns “/Users/gabrielbridges/.pyenv/shims/python”).

My C and C++ compilers are the default CLANG compilers provided by OS X.

For all of my ROOT builds I have followed the standard cmake procedure:

  1. cmake /path/to/source -Dbuiltin_glew=ON DCMAKE_INSTALL_PREFIX=/Path/to/install
  2. make -j2
  3. make install

These steps work perfectly for install ROOT on my machine and when I launch root from my command line I have complete functionality.
For my initial installation attempt I did not specify a python interpreter path with the “PYTHON_EXECUTABLE” option but noticed that CMAKE found my pyenv interpreter

Found Python: /Users/gabrielbridges/.pyenv/shims/python (found version "3.8.0") found components: Interpreter Development 
Found PythonInterp: /Users/gabrielbridges/.pyenv/shims/python (found version "3.8") 

After completing installation I launched root from the command line and ran a few tests and everything worked (I even laughed a GEANT simulation which produces a root tree as an output and it ran perfectly), however, when I launch python and “import ROOT” I am met with a set fault error

 *** 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/gabrielbridges/Root/root_install/lib/libPyROOT.so] PyUnicode_InternFromString /var/folders/dc/tyygd6sd395gk8f7qcpq00040000gn/T/python-build.20191105225251.16745/Python-3.8.0/Objects/unicodeobject.c:15323
[/Users/gabrielbridges/Root/root_install/lib/libPyROOT.so] PyROOT::CreatePyStrings() (no debug info)
[/Users/gabrielbridges/Root/root_install/lib/libPyROOT.so] PyInit_libPyROOT (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyImport_LoadDynamicModuleWithSpec (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _imp_create_dynamic (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] cfunction_vectorcall_FASTCALL (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyVectorcall_Call (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyFunction_Vectorcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] object_vacall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyImport_ImportModuleLevelObject (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyEval_EvalCode (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] builtin_exec (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] cfunction_vectorcall_FASTCALL (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyVectorcall_Call (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyFunction_Vectorcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] object_vacall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyImport_ImportModuleLevelObject (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyEval_EvalCode (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] builtin_exec (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] cfunction_vectorcall_FASTCALL (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyVectorcall_Call (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyFunction_Vectorcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] call_function (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] function_code_fastcall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] object_vacall (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyImport_ImportModuleLevelObject (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyEval_EvalCode (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyRun_InteractiveOneObjectEx (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyRun_InteractiveLoopFlags (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] PyRun_AnyFileExFlags (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] Py_RunMain (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] pymain_main (no debug info)
[/Users/gabrielbridges/.pyenv/versions/3.8.0/bin/python] Py_BytesMain (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
[<unknown binary>] (no debug info)

After investigating I found a few users with identical problems to my own and the suggestion that my problem was a mismatch in my system’s python and the python being used by ROOT. I cleaned and reinstalled ROOT with the new cmake option “PYTHON_EXECUTABLE” pointing to my Python installation. I noticed no difference in the output from cmake and running “import ROOT” returns the same error as before.

My question to the ROOT forums is, has anyone faced this problem before and managed to resolve it? If so, how?

_ROOT Version: 6.20.04
_Platform: Mac OSX 10.15.5 (Catalina)
_Compiler: CLANG/CLANG++
_Python: 3.8.0


Hi,

Could you check that ROOT actually built with your system Python installation?

You can run:

root-config --python-version

and to be completely sure, you can inspect the CMakeCache.txt file in your build directory and check for PYTHON_EXECUTABLE, PYTHON_INCLUDE_DIRS and PYTHON_LIBRARIES. Do they point to the system Python installation you wanted to build ROOT with?

Also as a reference, this seems a related post, see my answers and @amadio 's

I think the problem when compiling ROOT on MacOs is that the system libraries and the brew packages are compiled with different compilers so you have problems during linking or during execution.
The trick is to use or only the system libraries or only the brew ones. In the case of MacOS Catalina you are lucky because Python 3 is included by default with the system, so you might have better luck compiling ROOT from sources.
As far as I know there are five options:

  • Install ROOT precompile-binaries (this is the most straghtforward option but last time I checked only Python2 was supported)
  • Compile ROOT from sources (you have complete freedom but many things can go wrong if you are not careful)
  • Install ROOT using brew
  • Install ROOT using conda
  • Stop buying Apple products and get a real OS … joking.

@LastStarDust Thank you for your prompt reply,
root-config --python-version returns 3.8.0

in my CMakeCache.txt I have

PYTHON_EXECUTABLE-ADVANCED:INTERNAL=1
PYTHON_EXECUTABLE:INTERNAL=/Users/gabrielbridges/.pyenv/shims/python
PYTHON_INCLUDE_DIRS:INTERNAL=/Users/gabrielbridges/.pyenv/versions/3.8.0/include/python3.8
PYTHON_LIBRARIES:INTERNAL=/Users/gabrielbridges/.pyenv/versions/3.8.0/lib/libpython3.8.a

All of which point to the correct installation of python.

I’ve installed ROOT from source.

Just to check that I understand what you are saying:
The error in my installation is that I have used Homebrew and pyenv to install python on my machine, as such these use Brew’s compilers and not my system’s but, when I install ROOT I use my system’s compiler and not Brew’s.

If I understand correctly there is no way for me to install ROOT from source and use the Pyenv installation of python I currently have.

Thank you for your efforts, I’ll try to stick to my system’s python next time I reinstall.

Was your python compiled by the same compiler as ROOT?

BTW. I can see “libpython3.8.a” which suggests that this is an archive library … maybe you need the “shared” python library instead.

@Wile_E_Coyote
I’m not entirely sure about the compiler I used for python but I assume it was provided by Homebrew, I installed pyenv with brew install pyenv and then python with pyenv install 3.8. ROOT is being compiled with the default Apple Clang and Clang++ compilers. I assume this is the source of my problems.

The .a was of concern for me but it is the only library I have in my pyenv distribution.

I don’t think it is unimportant.
ROOT’s python related libraries are explicitly linked against it.
This may create run-time problems.
I really think the linker should use a “shared” python library.

I confirm that you need shared Python libraries to compile ROOT with Python support.

As for the compiler question, after asking around in the forum, my impression is that nobody ever tried to use brew pyenv + manually compiled ROOT, so you are more or less on your own if you choose to go that way. I eventually gave up on pyenv and settled for Anaconda Python + Anaconda ROOT (it was not my personal machine however). I understand that you want to use pyenv (I use it too because it is so handy). I personally do development on Ubuntu and have never had any issue with ROOT compiling, so my advice would be to install Ubuntu on dual boot or as VM.

AFAIK Anaconda uses it’s own gcc compiler so don’t bother at all, if you want to build anything with another compiler.

Thank you both very much! The problem was not an incompatibility between the ROOT and Python compilers, it was the lack of a shared Python library.

Be default Pyenv does not build python shared libraries but this can be fixed with the following option:

env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install X.X.X

where X.X.X is the version number you wish to install
After that configured pyenv as you would normally (i.e. pyenv global X.X.X)
And then build and install ROOT, I did not need to specify the path to my compiler though using the PYTHON_EXECUTABLE option can’t hurt.

Again thank you both for all of your help.

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