Building ROOT after updating Python

Hi all.

The problem I am facing is rather simple, but yet I have not managed to solve it for 2 days.

The situation is the following: I have built ROOT 6.12.06 from source on my Mac OSX High Sierra (10.13) with Python 2.7.10 preinstalled. This has worked taking into account [1].

Some days later, I needed to update python for some other application. Now it is version 2.7.15. In particular,
/usr/local/bin/python links to /usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/Python. Of course, pyROOT does not work anymore (i.e. doing “import ROOT” in the python script gives the error

unknown8C8590C2EBA4:rootbuild conni$ python
Python 2.7.15 (default, May 1 2018, 16:44:08)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
import ROOT
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6

So, what I did a couple of times now was to reset the path to the python environment and rebuild ROOT6 from source. I tried the following ways: First, I tried to change the link in the [2], which doesn’t work. Second, I tried to configure (and then rebuild from source) with --with-python-libdir and --with-python-incdir options [3], which also doesn’t work. Third, I added the path (/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/Python) which anyway is linked to by /usr/local/bin/python explicitly to the path as first directory (i.e. before /usr/local/bin/python) [3-4], which also does not bring the desired result.
This I do not understand, because python seems to be picked up correctly in the configure step: below I print you the output of the ./configure script in the last iteration (adding the python path to $PATH and running configure without options):

Checking for PyROOT prerequisites … yes
Checking for Python.h … /usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/include/python2.7
Checking for python2.7, libpython2.7, libpython, python, or Python … /usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib

Btw everytime I build root, I build it according to [1].

Still: is there something I am missing or doing wrong?

Thank you for any advice!

[1] - Problem building ROOT 6.12 on Mac OS X High Sierra
[2] - Trouble importing pyROOT on Mac OS X 10.11.1
[3] - Trouble importing pyROOT on OSX 10.9 Mavericks
[4] - pyROOT: Fatal Python error: PyThreadState_Get

The problem you have is likely due to incompatible compilers being used to build the Python you want to use and ROOT, or the wrong library being loaded at runtime. Your Python was built with [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] as indicated above. In order for ROOT to work with Python, you must build ROOT with the same compiler that was used to build Python. Also, you must ensure that the library paths are such that the right Python library is found first, unless you use RPATH to link (option -Drpath=ON in CMake). It could be that you built against Python 2.7.15, but the library being loaded at runtime is still from Python 2.7.10, in which case it will not work. When configuring, I recommend to use CMake, and pass only -DPYTHON_EXECUTABLE=/usr/local/bin/python when configuring. Also, check that all python libraries are picked for the correct version of Python. For example, in my machine, I get:

-- Found PythonInterp: /usr/bin/python3.6 (found version "3.6.5") 
-- Found PythonLibs: /usr/lib/ (found version "3.6.5") 
-- Found NUMPY: /usr/lib64/python3.6/site-packages/numpy/core/include (found version "1.13.3") 

when using cmake ~/src/root -DPYTHON_EXECUTABLE=$(which python3.6). In your case, you should see found version 2.7.15 both for the interpreter and libraries.

Dear amadio.

You are right, the cmake configuration (cmake ../root-6.12.06/ -Dxml=ON) has yielded this:

– Found PythonInterp: /usr/local/bin/python (found version “2.7.15”)
– Found Python interpreter version 2.7
– Found PythonLibs: /usr/lib/libpython2.7.dylib (found version “2.7.10”)
– Found NUMPY: /usr/local/lib/python2.7/site-packages/numpy/core/include (found version “1.14.3”)

So the link was not correct after all. Frankly I thought that using 2.7.15 would be compatible with 2.7.10 libraries.

In order to make things more complicated now, I installed python 3.6.5, added the proper ref to the $PATH (/usr/local/opt/python/libexec/bin) and reconfigured, now also paying attention that cmake picks up the proper version of python and the libraries (cmake ../root-6.12.06/ -Dxml=ON -DPYTHON_EXECUTABLE=/usr/local/opt/python/libexec/bin/python). Then I built ROOT6 again following [1] of my previous post. And things finally work!

Thank you a lot once more, amadio!


1 Like

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