Problem with Installing PyRoot


_ROOT Version: 6.17
_Platform: macOS 10.12.6
Compiler: Not Provided


Hi, I built root following the generic instruction on https://root.cern.ch/building-root. By default, once the installation is done, I should be able to do import ROOT in python. However, when I tried in the python interactive session, it segfault me.

Here is my python version:

Python 3.6.5 |Anaconda custom (64-bit)| (default, Apr 26 2018, 08:42:37) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

And here is my seg fault message:

*** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/Users/xinxiang/anaconda3/lib/libpython3.6m.dylib] PyUnicode_InternFromString (no debug info)
[/Users/xinxiang/Downloads/build/lib/libPyROOT.so] PyROOT::CreatePyStrings() /Users/xinxiang/Downloads/root/bindings/pyroot/src/PyStrings.cxx:64
[/Users/xinxiang/Downloads/build/lib/libPyROOT.so] PyInit_libPyROOT /Users/xinxiang/Downloads/root/bindings/pyroot/src/RootModule.cxx:848

[/Users/xinxiang/anaconda3/bin/python] _PyImport_LoadDynamicModuleWithSpec (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _imp_create_dynamic (no debug info)
[/Users/xinxiang/anaconda3/bin/python] PyCFunction_Call (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyFunction_FastCallDict (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyObject_FastCallDict (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)
[/Users/xinxiang/anaconda3/bin/python] PyImport_ImportModuleLevelObject (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/xinxiang/anaconda3/bin/python] builtin_exec (no debug info)
[/Users/xinxiang/anaconda3/bin/python] PyCFunction_Call (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyFunction_FastCallDict (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyObject_FastCallDict (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)
[/Users/xinxiang/anaconda3/bin/python] PyImport_ImportModuleLevelObject (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/xinxiang/anaconda3/bin/python] builtin_exec (no debug info)
[/Users/xinxiang/anaconda3/bin/python] PyCFunction_Call (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] fast_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] call_function (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyFunction_FastCallDict (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyObject_FastCallDict (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)
[/Users/xinxiang/anaconda3/bin/python] PyImport_ImportModuleLevelObject (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/Users/xinxiang/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/Users/xinxiang/anaconda3/bin/python] PyRun_InteractiveOneObjectEx (no debug info)
[/Users/xinxiang/anaconda3/bin/python] PyRun_InteractiveLoopFlags (no debug info)
[/Users/xinxiang/anaconda3/bin/python] PyRun_AnyFileExFlags (no debug info)
[/Users/xinxiang/anaconda3/bin/python] Py_Main (no debug info)
[/Users/xinxiang/anaconda3/bin/python] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)

Hi,

are you sure that this is the python against which root was built?

Cheers,
D

Hi,

I do have several python versions installed. How to check which version the root is built with?

Following your suggestion, I tried with python2.7:

Python 2.7.8 (default, Jul 13 2014, 17:11:32) 
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

And here is the error when doing import ROOT:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ROOT.py", line 24, in <module>
    import cppyy
  File "cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: dynamic module does not define init function (initlibPyROOT)

Thanks

Hi,

when you ran CMake you should have seen something like

-- Found PythonInterp: /usr/bin/python (found version "2.7.10") 

try that python after making sure the environment is properly set, i.e. by sourcing the rootInstallDir/bin/thisroot.sh script.

Cheers,
D

Hi,

I check, it says
found PythonInterp: /Users/xinxiang/anaconda3/bin/python (found version "3.6.5")
which is the same version giving me seg fault above. I made sure I source the path/to/root/bin/thisroot.sh

Xin

Are you sure the python interpreter and the libraries used are the same? The error you are getting is very typical of building against Python 2 and trying to use Python 3 afterwards to load the module. Please make sure to use GCC from anaconda to compile ROOT as well, or you will probably hit ABI incompaitbilities between anaconda and system libraries.

Hi It seems that this is quite an issue since the last OSX update.

Tired of the horrible practice of chowning the system python folder every few months in order to work with a new python dev packages, I cleaned out my local python env to switch to a pure homebrew version. I can now get root to compile from source but it still refuses to work with python. Some preliminary googling suggests a cmake issue.

the command I use to make is

cmake ../root-release/root/ -Droofit=ON -Dminuit2=ON -DPYTHON_EXECUTABLE=/usr/bin/python -DPYHTON_INCDIR=/usr/local/include/ -DPYTHON_LIBDIR=/usr/lib

or some combination thereof (I’ve tried a few now). This combination doesn’t mention a PythonInterp or a PythonLibs version but occasionally (when trying with different commands It mentions that one or the other is either version "2.7.15" or version "2.7.10" which I don’t know how to control.

now althogh it compiles when trying to run with python I get a:

$ python
Python 2.7.15 (default, Oct  2 2018, 11:42:04) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6

and regular root segfaults during loading (meaning the picture hangs on the screen indefinitely):

$ root
**error:** unable to read PCH file /Users/vince/root/etc/allDict.cxx.pch: 'No such file or directory'
**fatal error:** PCH file '/Users/vince/root/etc/allDict.cxx.pch' not found: module file not found

*** Break *** segmentation violation

I’ve seen lots of post about this over the years but they give seemingly contradicting advice so although I don’t believe that I have the same issue as xxiang4, it seems that more formal instructions as to finding and specifying python paths and libraries might be nice.

You should not specify PYTHON_INCDIR and PYTHON_LIBDIR by hand. That’s why your configuration is not working. You are using python from one place (/usr), and the libraries from another (/usr/local). You should only use -DPYTHON_EXECUTABLE=/full/path/to/python, then only use ROOT with that particular python. Python libraries are not compatible for different versions. In addition, you need to use the same compiler (or a compatible one) to the one that was used to compile the python you want to use. This is because ROOT needs to link against libstdc++ and libpythonX.Y, and they need to be ABI compatible, or libPyROOT will be broken. When you set only PYTHON_EXECUTABLE, the calls to find_package(PythonInerp) and find_package(PythonLibs) ensure that only matching versions are found. If you set by hand, you force CMake to find incompatible versions. In your CMake output, you should see which ones were selected, like this:

-- Found PythonInterp: /usr/bin/python3.7 (found version "3.7") 
-- Found PythonLibs: /usr/lib/libpython3.7m.so (found version "3.7.0") 
-- Found NUMPY: /usr/lib/python3.7/site-packages/numpy/core/include (found version "1.14.5") 

If any of the above doesn’t match, then ROOT will be broken in the end.

No joy im afraid. This is actually a configuration I’ve tried before. Following the steps:

  1. $which python
  2. cmake builddir sourcedir -DPYTHON_EXECUTABLE=/result/of/previous/step
  3. make

In my cmake output I get:

-- Found PythonInterp: /usr/local/bin/python (found version "2.7.15") 
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.10") 

now my root interpreter doesn’t hang but I still get no python bindings:

$ python
Python 2.7.15 (default, Oct  2 2018, 11:42:04) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6```

Something is strange with your environment if you get /usr/local/bin/python but /usr/lib/libpython2.7.dylib to match. You should fix your environment to get /usr/local/lib/libpython2.7.dylib (presumably the same version as /usr/local/bin/python. But if you’re on Mac, just use brew install root, it should work. You will only have to set PYTHONPATH by hand afterwards.

Hi @amadio, I have tried /usr/bin/python2.7 and import ROOT works with no error message. That’s a system default version I think. How do I specify exactly the python version when compiling ROOT? For example, I would like it to work with /Users/xinxiang/anaconda3/bin/python to use other library.

I really wish the official installation procedure has clearly state issues with versions. I feel like most people are going down the wrong path the first time.

Using -DPYTHON_EXECUTABLE=/Users/xinxiang/anaconda3/bin/python should be enough. But please check that the libraries found match the python from anaconda. And if you get linking errors, please use GCC from anaconda as well.

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