PyRoot crashes with ROOT 6.11/02 and Python3

Hi experts, I have python 3.6.2 installed via anaconda and I installed ROOT 6.11/02 via usual cmake on OSX v10.13 with Xcode 9.0.1

In the python prompt when I call import ROOT, I get the following crash :

lt00750458:~ Sanmay$ python
Python 3.6.2 |Anaconda, Inc.| (default, Sep 21 2017, 18:29:43)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

from ROOT import *

*** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[] (no debug info)
[/anaconda3/lib/libpython3.6m.dylib] PyUnicode_InternFromString (no debug info)
[/Users/Sanmay/root_build/lib/libPyROOT.so] PyROOT::CreatePyStrings() /Users/Sanmay/root-6.11.02/bindings/pyroot/src/PyStrings.cxx:64
[/Users/Sanmay/root_build/lib/libPyROOT.so] PyInit_libPyROOT /Users/Sanmay/root-6.11.02/bindings/pyroot/src/RootModule.cxx:848
[/anaconda3/bin/python] _PyImport_LoadDynamicModuleWithSpec (no debug info)
[/anaconda3/bin/python] _imp_create_dynamic (no debug info)
[/anaconda3/bin/python] PyCFunction_Call (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] _PyFunction_FastCallDict (no debug info)
[/anaconda3/bin/python] _PyObject_FastCallDict (no debug info)
[/anaconda3/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)
[/anaconda3/bin/python] PyImport_ImportModuleLevelObject (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/anaconda3/bin/python] builtin_exec (no debug info)
[/anaconda3/bin/python] PyCFunction_Call (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] _PyFunction_FastCallDict (no debug info)
[/anaconda3/bin/python] _PyObject_FastCallDict (no debug info)
[/anaconda3/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)
[/anaconda3/bin/python] PyImport_ImportModuleLevelObject (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/anaconda3/bin/python] builtin_exec (no debug info)
[/anaconda3/bin/python] PyCFunction_Call (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] fast_function (no debug info)
[/anaconda3/bin/python] call_function (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] _PyFunction_FastCallDict (no debug info)
[/anaconda3/bin/python] _PyObject_FastCallDict (no debug info)
[/anaconda3/bin/python] _PyObject_CallMethodIdObjArgs (no debug info)
[/anaconda3/bin/python] PyImport_ImportModuleLevelObject (no debug info)
[/anaconda3/bin/python] _PyEval_EvalFrameDefault (no debug info)
[/anaconda3/bin/python] _PyEval_EvalCodeWithName (no debug info)
[/anaconda3/bin/python] PyRun_InteractiveOneObject (no debug info)
[/anaconda3/bin/python] PyRun_InteractiveLoopFlags (no debug info)
[/anaconda3/bin/python] PyRun_AnyFileExFlags (no debug info)
[/anaconda3/bin/python] Py_Main (no debug info)
[/anaconda3/bin/python] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
[] (no debug info)

Can you please give me some insight what went wrong ? ROOT and python are working fine individually.

Thanks,
Sanmay

Have you tried simply:

import ROOT

There is a bug report about

from ROOT import *

not working with Python 3: https://sft.its.cern.ch/jira/projects/ROOT/issues/ROOT-8931. As well as a recent merge that prevents it from being used: https://github.com/root-project/root/pull/825

Yes, I did try import ROOT and it gives identical crash message and the shell exits from python .

The construct from ROOT import * is not supported with Python 3.x. For more details, please see ROOT-8931. If you still have crashes with Python 3.x when using only import ROOT and you configured ROOT with -Dpython3=ON, please let us know and we will investigate. Cheers,

This crash has nothing to do with the import statement or ROOT-8931. It happens right after loading libPyROOT by dld, when the ctors for global objects are being run. That is well before anything happens to __all__.

It’s most likely a configuration issue w/ PyROOT having been build for another python than the one used at run-time. Internalization of python strings is nothing but stuffing some very common ones (such as e.g. __name__) in a dict held by the interpreter, so that these common strings are shared across all uses and not recreated all the time. That’s not going to crash by itself, but unicode comes in 2 and 4 byte varieties, so count your luck if only half the bytes expected are delivered …

Anyway, that anaconda python is not in a path that the configuration scripts will find, so it must be explicitly specified for this to work.

Hi,

just to inform that the problem remains. I tried the following cmake build option :

cmake -DPYTHON_EXECUTABLE=/anaconda3/bin/python3.6 -Dpython3=ON …/root-6.11.02

Best,
Sanmay

Another user in another topic has indicated that the PYTHON_EXECUTABLE flag is not sufficient, but that you will additionally need to set the flags PYTHON_INCLUDE_DIR and PYTHON_LIBRARY.

Given the number of people who have trouble with this (pretty much every other topic, or so it seems like), I’d really recommend to add a setup.py so that folks can do a normal python setup.py install for the python that they want or pip user or virtualenv, or what have you.

PyROOT has two parts: an extension module and a few python files. There’s straightforward support for both in setuptools. You only need to pick up some extra flags through $ROOTSYS and/or root-config. Takes ~100 lines of python, most of it boilerplate, and you’re off to the races.

Here’s a basic example:
https://bitbucket.org/wlav/cpycppyy/src/dafe91690df90e9aa82e3a49e220ff6dc09d7972/setup.py?at=master&fileviewer=file-view-default

where you can add e.g. the ROOT include path using something like:

def get_include_path():
   try:
       root_install = os.environ["ROOTSYS"]
       return os.path.join(root_install, 'include')
   except KeyError:
       pass
    rc = subprocess.check_output(['root-config', '--cflags'])
    return rc.decode("utf-8")

Similarly for ldflags. Declare ROOT.py etc. to be standalone modules (they are) and done. None of this will bite or interfere with the cmake way of building/installing.

1 Like

Have a look at this post. I suspect that most people using anaconda have a bad LD_LIBRARY_PATH, so anaconda software is trying to use incompatible libraries from the system. This looks like it’s the case here as well.

A priori I don’t see thisroot.sh changing system path in LD_LIBRARY_PATH, only adding $ROOTSYS/lib, which is innocuous. For Python, adding $ROOTSYS/lib to PYTHONPATH would be undesirable when running anaconda, but that’s a simple matter of disabling cmake build python if a setup.py were provided and used.

Either way, what I read in this topic is folks having problem getting the right python picked up by cmake, which all happens before sourcing thisroot.sh.

Providing a setup.py is trivial, as described above, and will allow folks to deal with all the pythons they care to carry on their system in a systematic way. And again, since it’s so simple, all the time spent discussing it has taken more than the coding time would have been, so I’ve said my say am an done with it.

1 Like

Hi,

I am having the same problem. I’m using Anaconda on macOS 10.12 and I can’t import ROOT in Python.

However I have noticed that when I try to import ROOT, the error message points to the directory where ROOT was dowloaded (/Users/francesco/Downloads/root-6.11.02/) instead of the installation directory (/usr/local/root):

Python 3.6.2 |Anaconda, Inc.| (default, Sep 21 2017, 18:29:43) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import ROOT

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

ROOT has been built with options:

-DCMAKE_INSTALL_PREFIX=/usr/local/root
-Dpython3=ON

and it does pick up the correct Python.
LD_LIBRARY_PATH is set by ROOT and it is not touched by Anaconda.

Any help?
Thank you in advance.
Best regards.

Francesco

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