# Building ROOT after updating Python

**URL:** <https://root-forum.cern.ch/t/building-root-after-updating-python/28997>\
**Category:** ROOT\
**Tags:** python\
**Created:** [May 13, 2018, 1:14pm UTC](https://root-forum.cern.ch/t/building-root-after-updating-python/28997 "2018-05-13T13:14:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![heico](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@heico](https://root-forum.cern.ch/u/heico)\
**Post date:** [May 13, 2018, 1:14pm UTC](https://root-forum.cern.ch/t/building-root-after-updating-python/28997/1 "2018-05-13T13:14:42Z")

</div>

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 libPyROOT.so [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!  
heico

[1] - [Problem building ROOT 6.12 on Mac OS X High Sierra - #7 by heico](https://root-forum.cern.ch/t/problem-building-root-6-12-on-mac-os-x-high-sierra/28797/7)  
[2] - [Trouble importing pyROOT on Mac OS X 10.11.1 - #8 by edwrdg13](https://root-forum.cern.ch/t/trouble-importing-pyroot-on-mac-os-x-10-11-1/21000/8)  
[3] - [Trouble importing pyROOT on OSX 10.9 Mavericks](https://root-forum.cern.ch/t/trouble-importing-pyroot-on-osx-10-9-mavericks/17287)  
[4] - [pyROOT: Fatal Python error: PyThreadState\_Get - #3 by mrluca87](https://root-forum.cern.ch/t/pyroot-fatal-python-error-pythreadstate-get/24427/3)

---

<div class="post-metadata">

**Author:** ![amadio](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/amadio/32/12562_2.png) [@amadio](https://root-forum.cern.ch/u/amadio)\
**Post date:** [May 14, 2018, 5:46am UTC](https://root-forum.cern.ch/t/building-root-after-updating-python/28997/2 "2018-05-14T05:46:15Z")

</div>

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](https://root-forum.cern.ch/t/importerror-no-module-named-libpyroot-after-install-anaconda/28862/3). 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:

```auto
-- Found PythonInterp: /usr/bin/python3.6 (found version "3.6.5") 
-- Found PythonLibs: /usr/lib/libpython3.6m.so (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.

---

<div class="post-metadata">

**Author:** ![heico](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@heico](https://root-forum.cern.ch/u/heico)\
**Post date:** [May 14, 2018, 11:04am UTC](https://root-forum.cern.ch/t/building-root-after-updating-python/28997/3 "2018-05-14T11:04:39Z")

</div>

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!

Cheers,  
heico

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 28, 2018, 11:04am UTC](https://root-forum.cern.ch/t/building-root-after-updating-python/28997/4 "2018-05-28T11:04:42Z")

</div>

Closed on May 28, 2018, 11:04am UTC

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