Trouble importing pyROOT on Mac OS X 10.11.1

Hi,

My ROOT installation seems to be working fine, but when I try to import pyROOT, I get this error: [code]Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 12:54:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import ROOT
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6

[/code]. I believe this has to do with ROOT being built against one python but being imported against another, but I’m not sure how to resolve this.

I’ve followed the thread here: [url]Trouble importing pyROOT on OSX 10.9 Mavericks
and I have: otool -L /root/lib/libPyROOT.so /root/lib/libPyROOT.so: @rpath/libPyROOT.so (compatibility version 0.0.0, current version 0.0.0) @rpath/libTree.so (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10) @rpath/libRIO.so (compatibility version 0.0.0, current version 0.0.0) @rpath/libCore.so (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1).

Based on the thread, I tried this: install_name_tool -change libpython2.7.dylib /Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib libPyROOT.so but the error still appears.

I’ve tried to debug this but without success, and I would really appreciate if anyone would be able to help out with this.

Thanks!

Hi,

the Python module is called ROOT. So you should type

Import ROOT

D

Hi,

Thanks for the reply!

I recieve the following error when I type import ROOT:

[code]Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 12:54:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import ROOT
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6
dhcp-18-189-16-11:lib edward$

[/code]

Best,

Edward

Hi Edward,

might I ask you not to change your previous posts? It might result in something misleading for the future readers :wink:
Do you have several distributions of Python on your system?

D

Hi,

Sorry about that. The preinstalled python distribution is located at /usr/bin/python, but the python distribution that I’m using is located at: /Library/Frameworks/Python.framework/Versions/2.7/bin/python I’ve attempted to direct pyROOT to the second distribution by modifying my bash file: [code]#ROOT
export ROOTSYS=/root
export PATH=$ROOTSYS/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH

#PYROOT
export PYTHONDIR=/Library/Frameworks/Python.framework/Versions/2.7/bin/python
export PATH=$ROOTSYS/bin:$PYTHONDIR/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$PYTHONDIR/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH

Setting PATH for Python 2.7

The orginal version is saved in .bash_profile.pysave

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH[/code]

Best,

Edward

I think that there might be a conflict due to the presence of two installations at config time.
Is it an option to try and remove the non-Apple python and proceed with a new ROOT build?

D

Edward,

The other way around should be preferred.

[quote=“edwrdg13”]I’ve attempted to direct pyROOT to the second distribution by modifying my bash file:[/quote]PyROOT is not affected by any of those (not with the setup you show above anyway).

You need to make sure that the python version that you used to build PyROOT comes first in PATH. However, what you do here:[quote=“edwrdg13”]export PYTHONDIR=/Library/Frameworks/Python.framework/Versions/2.7/bin/python[/quote]is setting PYTHONDIR to the python binary (which is not a directory). Either way, the system python is not affected by envars, and if it were, you’d want to set PYTHONHOME.

From there:[quote=“edwrdg13”]export PATH=$ROOTSYS/bin:$PYTHONDIR/bin:$PATH[/quote]does not do you any good, as $PYTHONDIR/bin (or lib) does of course not exist.

What you have to do, is check what which python gives you, and if that is not the system one (as you seem to want for this setup), then add ‘/Library/Frameworks/Python.framework/Versions/2.7/bin’ to PATH (and ‘/Library/Frameworks/Python.framework/Versions/2.7/lib’ to (DY)LD_LIBRARY_PATH.

HTH,
Wim

Hi,

typing ‘which python’ returns: dhcp-18-189-16-11:~ edward$ which python /Library/Frameworks/Python.framework/Versions/2.7/bin/python

I’ve attempted to do this. My bash file is now:

[code]# Setting PATH for Python 2.7

The orginal version is saved in .bash_profile.pysave

PATH=“/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}”
export PATH
export LD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/2.7/lib

ROOT
export ROOTSYS=/root
export PATH=$ROOTSYS/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH

#PYROOT
export PYTHONDIR=/Library/Frameworks/Python.framework/Versions/2.7/bin/
export PATH=$ROOTSYS/bin:$PYTHONDIR/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$PYTHONDIR/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH
[/code]

Trying to import ROOT still returns the same error: >>> import ROOT Fatal Python error: PyThreadState_Get: no current thread Abort trap: 6

Is there anything else that you suggest I do?

Thanks,

Edward

Edward,

what does your current ‘otool -L $ROOTSYS/lib/libPyROOT.so’ give you? (Above that points to the system python, but then above you also state that you ran install_name_tool.)

What is the version of the python binary that you are running now? (Above you print it, the last you cut if off. I have 2.7.10 under /usr/bin, and 2.7.3 under /Library; I have a pending update so maybe that brings me to 2.7.11 that you have, or something is still not proper.)

One way or another the interpreter loaded by the binary is still different from the one loaded by libPyROOT.so. Since it lives in a shared library in both cases, it has to be the same for things to work. So, compare:otool -L `which python`with:otool -L $ROOTSYS/lib/libPyROOT.so and see whether there are still any differences left.

Cheers,
Wim

Hi Wim,

Those return:

edward$ otool -L `which python` /Library/Frameworks/Python.framework/Versions/2.7/bin/python: /Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

and edward$ otool -L $ROOTSYS/lib/libPyROOT.so /root/lib/libPyROOT.so: @rpath/libPyROOT.so (compatibility version 0.0.0, current version 0.0.0) @rpath/libTree.so (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10) @rpath/libRIO.so (compatibility version 0.0.0, current version 0.0.0) @rpath/libCore.so (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

Do you know the best way of making those the same? Would it be worth uninstalling python and reinstalling ROOT as dpiparo suggested?

Best,

Edward

Edward,

yes, I’d reconfigure (with current PATH; I’m not sure about cmake, but the configure script used to pick python up from there) and rebuild. (install_name_tool might work and the two should be binary compatible, but those are famous last words.)

Cheers,
Wim

Hi,

To reconfigure would I download the source and compile with ./configure --with-python-incdir=... --with-python-libdir=..., or is there a better way?

Best,

Edward

Edward,

if the right python is first in PATH, the configure script will pick it up with no further need of incdir/libdir. I don’t know about cmake (never used it).

Cheers,
Wim

Hi,

Thanks for the advice. I’ve recompiled ROOT from the source, and it seems to be working fine. When trying to import ROOT, now, I receive this error: [code]>>> import ROOT
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named ROOT

[/code]

Do you know how to resolve this?

Cheers,

Edward

Edward,

assuming that it build (check $ROOTSYS/lib for ROOT.py), make sure that $ROOTSYS/lib is in the $PYTHONPATH envar.

Cheers,
Wim

Hi,

I’m not sure if I’m misunderstanding. I modified the bash profile to: [code]#ROOT
export ROOTSYS=/Applications/root_v6.04.16
export PATH=$ROOTSYS/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$ROOTSYS/lib

[/code]

However, I’m still receiving the error Fatal Python error: PyThreadState_Get: no current thread Abort trap: 6

otool seems to suggest that ROOT is still using the system python distribution:

otool -L libPyROOT.so libPyROOT.so: @rpath/libPyROOT.so (compatibility version 0.0.0, current version 0.0.0) @rpath/libTree.so (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10) @rpath/libRIO.so (compatibility version 0.0.0, current version 0.0.0) @rpath/libCore.so (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

Is there a way to manually change this? Or is there some other fix?

Best,
Edward

Edward,

config.log should show which python was picked up. Check that to see what went wrong. There are no paths pointing directly to /System hardwired in configure, so I don’t see how it can pick up the system ones if the python in PATH is the /Library one.

Cheers,
Wim