# PyRoot crashes with ROOT 6.11/02 and Python3

**URL:** <https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599>\
**Category:** ROOT\
**Tags:** python, root\
**Created:** [October 17, 2017, 4:14pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599 "2017-10-17T16:14:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanmayphy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sanmayphy/32/13917_2.png) [@sanmayphy](https://root-forum.cern.ch/u/sanmayphy)\
**Post date:** [October 17, 2017, 4:14pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/1 "2017-10-17T16:14:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [October 17, 2017, 4:56pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/2 "2017-10-17T16:56:08Z")

</div>

Have you tried simply:

```python
import ROOT

```

There is a bug report about

```python
from ROOT import *

```

not working with Python 3: [https://sft.its.cern.ch/jira/projects/ROOT/issues/ROOT-8931](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](https://github.com/root-project/root/pull/825)

---

<div class="post-metadata">

**Author:** ![sanmayphy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sanmayphy/32/13917_2.png) [@sanmayphy](https://root-forum.cern.ch/u/sanmayphy)\
**Post date:** [October 17, 2017, 5:08pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/3 "2017-10-17T17:08:38Z")

</div>

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

---

<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:** [October 17, 2017, 8:23pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/4 "2017-10-17T20:23:24Z")

</div>

The construct `from ROOT import *` is not supported with Python 3.x. For more details, please see [ROOT-8931](https://sft.its.cern.ch/jira/browse/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,

---

<div class="post-metadata">

**Author:** ![wlav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@wlav](https://root-forum.cern.ch/u/wlav)\
**Post date:** [October 17, 2017, 10:29pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/5 "2017-10-17T22:29:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sanmayphy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sanmayphy/32/13917_2.png) [@sanmayphy](https://root-forum.cern.ch/u/sanmayphy)\
**Post date:** [October 18, 2017, 6:20pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/6 "2017-10-18T18:20:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [October 18, 2017, 9:13pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/7 "2017-10-18T21:13:30Z")

</div>

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`.

> [@PyROOT cannot open file: "Error in \<TNetXNGFile::Open\>: \[FATAL\] Auth failed"](https://root-forum.cern.ch/t/pyroot-cannot-open-file-error-in-tnetxngfile-open-fatal-auth-failed/26593/20):
>
> @ksmith So it looks like you’re right. It’s an issue with SIP that can be worked around using a different, non-system python. However, that one flag alone is not enough. I had to do: cmake -Dall=On -DPYTHON\_EXECUTABLE=/usr/local/bin/python2 -DPYTHON\_INCLUDE\_DIR=/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/Headers -DPYTHON\_LIBRARY=/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib ../root/ pointing it at the Homebrew vers…

---

<div class="post-metadata">

**Author:** ![wlav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@wlav](https://root-forum.cern.ch/u/wlav)\
**Post date:** [October 18, 2017, 9:47pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/8 "2017-10-18T21:47:37Z")

</div>

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](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:

```auto
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.

---

<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:** [October 19, 2017, 12:53pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/9 "2017-10-19T12:53:36Z")

</div>

Have a look at [this post](https://root-forum.cern.ch/t/pyroot-cannot-open-file-error-in-tnetxngfile-open-fatal-auth-failed/26593/23?u=amadio). 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.

---

<div class="post-metadata">

**Author:** ![wlav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@wlav](https://root-forum.cern.ch/u/wlav)\
**Post date:** [October 19, 2017, 3:52pm UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/10 "2017-10-19T15:52:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![guescio](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/51bf81/32.png) [@guescio](https://root-forum.cern.ch/u/guescio)\
**Post date:** [October 23, 2017, 6:30am UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/11 "2017-10-23T06:30:16Z")

</div>

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`):

```auto
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:

```auto
-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

---

<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:** [November 6, 2017, 6:30am UTC](https://root-forum.cern.ch/t/pyroot-crashes-with-root-6-11-02-and-python3/26599/12 "2017-11-06T06:30:21Z")

</div>

Closed on November 6, 2017, 6:30am UTC

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