# Segfault when importing ROOT in python

**URL:** <https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713>\
**Category:** Newbie\
**Tags:** installation\
**Created:** [June 1, 2020, 8:30pm UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713 "2020-06-01T20:30:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevajrussell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@trevajrussell](https://root-forum.cern.ch/u/trevajrussell)\
**Post date:** [June 1, 2020, 8:30pm UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713/1 "2020-06-01T20:30:59Z")

</div>

I just installed ROOT but I can’t import it into python without a segfault error. I am on MacOs 10.15 and am using python 3.7.3. I installed root by activating the virtual environment I will be using and then the following:

wget [https://root.cern.ch/download/root\_v6.16.00.source.tar.gz](https://root.cern.ch/download/root_v6.16.00.source.tar.gz)  
tar -zxf root\_v6.16.00.source.tar.gz  
mkdir root-6.16.00\_builddir  
cd root-6.16.00\_builddir  
cmake …/root-6.16.00  
cmake --build .  
source bin/thisroot.sh  
python -m pip install root\_numpy

I am able to open root in terminal without error, but I get a segfault if I open python in terminal and try to import ROOT. It might be worth noting that when I did ‘cmake …/root-6.16.00,’ I got some error messages saying that certain things like PCRE, GIF, PNG, JPEG, and a lot more could not be found. Then it also said that certain tests failed, but I was still able to do the next step and open root later so I wasn’t sure if it was an issue.

Has anyone had a similar problem or have some advice for how to fix this? (Sorry if anything is unclear I am not great with this stuff)

---

<div class="post-metadata">

**Author:** ![ahesam](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahesam/32/19455_2.png) [@ahesam](https://root-forum.cern.ch/u/ahesam)\
**Post date:** [June 1, 2020, 10:10pm UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713/2 "2020-06-01T22:10:38Z")

</div>

What does the segfault say? I would get a segfault when I try to load ROOT into a python interpreter with a different version then the python version which I built ROOT against. This can happen if you have multiple python installation on your machine.

Is there a reason why you need specifically version 6.16? There are a couple more recent version available from [https://root.cern/downloading-root](https://root.cern/downloading-root) that you can use directly (no need for cmake).

---

<div class="post-metadata">

**Author:** ![trevajrussell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@trevajrussell](https://root-forum.cern.ch/u/trevajrussell)\
**Post date:** [June 2, 2020, 1:31am UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713/3 "2020-06-02T01:31:31Z")

</div>

Below is the full error message. I don’t think there’s any reason why I need to use that specific version, I just used the exact same commands that my professor said he used and I wasn’t sure how to do it otherwise. I don’t think the interpreter version is the issue because that did happen before I installed ROOT but I fixed it first. Is there a better way I should use to download it?

\*\*\* Break \*\*\* segmentation violation

[/usr/lib/system/libsystem\_platform.dylib] \_sigtramp (no debug info)

[/usr/lib/system/libsystem\_malloc.dylib] szone\_size (no debug info)

[/Users/Trevor/anaconda3/lib/libpython3.7m.dylib] PyUnicode\_InternFromString (no debug info)

[/Users/Trevor/root-6.16.00\_builddir/lib/libPyROOT.so] PyROOT::CreatePyStrings() /Users/Trevor/root-6.16.00/bindings/pyroot/src/PyStrings.cxx:64

[/Users/Trevor/root-6.16.00\_builddir/lib/libPyROOT.so] PyInit\_libPyROOT /Users/Trevor/root-6.16.00/bindings/pyroot/src/RootModule.cxx:848

[/Users/Trevor/anaconda3/bin/python] \_PyImport\_LoadDynamicModuleWithSpec (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_imp\_create\_dynamic (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyMethodDef\_RawFastCallDict (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyCFunction\_Call (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyFunction\_FastCallKeywords (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] object\_vacall (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyObject\_CallMethodIdObjArgs (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyImport\_ImportModuleLevelObject (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] builtin\_exec (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyMethodDef\_RawFastCallDict (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyCFunction\_Call (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyFunction\_FastCallKeywords (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] object\_vacall (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyObject\_CallMethodIdObjArgs (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyImport\_ImportModuleLevelObject (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] builtin\_exec (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyMethodDef\_RawFastCallDict (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyCFunction\_Call (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyFunction\_FastCallKeywords (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] call\_function (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] function\_code\_fastcall (no debug info)

[/Users/Trevor/anaconda3/bin/python] object\_vacall (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyObject\_CallMethodIdObjArgs (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyImport\_ImportModuleLevelObject (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalFrameDefault (no debug info)

[/Users/Trevor/anaconda3/bin/python] \_PyEval\_EvalCodeWithName (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyRun\_InteractiveOneObjectEx (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyRun\_InteractiveLoopFlags (no debug info)

[/Users/Trevor/anaconda3/bin/python] PyRun\_AnyFileExFlags (no debug info)

[/Users/Trevor/anaconda3/bin/python] pymain\_main (no debug info)

[/Users/Trevor/anaconda3/bin/python] main (no debug info)

[/usr/lib/system/libdyld.dylib] start (no debug info)

[] (no debug info)

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [June 2, 2020, 10:16am UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713/4 "2020-06-02T10:16:23Z")

</div>

Here is the compilation guide, with a link to prerequisites:  
[https://root.cern/building-root](https://root.cern/building-root)  
Even if you get an already compiled binary version (from the link ahesam gave you), it won’t hurt to install the prerequisites.  
If you go for the binaries, just get the latest Pro release binary for your OS and clang. Note that those binaries were compiled for some Python version (if it was python2.xx it won’t work with python 3.xx); I don’t use MacOS, so I don’t know the version used to generate the binaries (for Ubuntu 18.04, for instance, it is compiled with python2, so the root binary doesn’t work with python3); if the binary doesn’t work you will need to compile your own.

---

<div class="post-metadata">

**Author:** ![ahesam](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahesam/32/19455_2.png) [@ahesam](https://root-forum.cern.ch/u/ahesam)\
**Post date:** [June 2, 2020, 11:11am UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713/5 "2020-06-02T11:11:33Z")

</div>

You can also check what version of python ROOT is built with using `root-config --python-version` after you sourced `thisroot.sh` (found in `<root_install_path>/bin`). Check if it’s the same version as the python you are trying to import ROOT in (which you say is 3.7.3).

---

<div class="post-metadata">

**Author:** ![trevajrussell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@trevajrussell](https://root-forum.cern.ch/u/trevajrussell)\
**Post date:** [June 3, 2020, 4:47am UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713/6 "2020-06-03T04:47:51Z")

</div>

When I do “root-config --python-version” nothing seems to print. I am not sure why because if I type “root-config --has-python” I get a yes.

---

<div class="post-metadata">

**Author:** ![trevajrussell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@trevajrussell](https://root-forum.cern.ch/u/trevajrussell)\
**Post date:** [June 3, 2020, 7:53am UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713/7 "2020-06-03T07:53:26Z")

</div>

I also tried using the binary installation instead. Now when I try to import ROOT in python I get this error “ImportError: dynamic module does not define module export function (PyInit\_libPyROOT)”

I think the issue is the python version. It says ROOT was built with 2.7.16 but I definitely need python3 so I don’t think the binaries are an option.

---

<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:** [June 3, 2020, 11:32am UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713/8 "2020-06-03T11:32:08Z")

</div>

> [@trevajrussell](#):
>
> When I do “root-config --python-version” nothing seems to print.

See [Loading...](https://sft.its.cern.ch/jira/browse/ROOT-10167). You need to update to one of the fixed versions at least.

BTW, if you are installing on Mac OS, I recommend installing from our binary releases, or from a package manager like Homebrew. See [root — Homebrew Formulae](https://formulae.brew.sh/formula/root) for more information.  
If you use anaconda, you should probably try to install [root from conda-forge](https://anaconda.org/conda-forge/root) rather than compile it yourself.

---

<div class="post-metadata">

**Author:** ![trevajrussell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@trevajrussell](https://root-forum.cern.ch/u/trevajrussell)\
**Post date:** [June 5, 2020, 4:09am UTC](https://root-forum.cern.ch/t/segfault-when-importing-root-in-python/39713/9 "2020-06-05T04:09:00Z")

</div>

I tried installing via homebrew but gave up and cut it short after it had been working on it for more than 24 hours. Is there something I could do to see a progress bar when installing with homebrew? It spent 24 hours without giving any indications after printing this:  
==\> Installing root  
Warning: Building root from source:  
The bottle hardcodes locations inside Xcode.app  
=\> cmake … -DCLING\_CXX\_PATH=clang++ -DCMAKE\_INSTALL\_ELISPDIR=/usr/local/Cellar/root/6.20.04\_2/share/emacs/site-lisp/root -DPYTHON\_EXECUTABLE=/  
==\> make install

I also just tried with anaconda instead and it installed pretty quickly but I get an error when importing ROOT. I checked and I get 3.8.2 for python --version and for root-config --python-version. This is the error I get:

Traceback (most recent call last):  
File “”, line 1, in   
File “/Users/Trevor/anaconda3/envs/myenv/lib/python3.8/site-packages/ROOT.py”, line 24, in   
import cppyy  
File “/Users/Trevor/anaconda3/envs/myenv/lib/python3.8/site-packages/cppyy.py”, line 61, in   
import libPyROOT as \_backend  
ImportError: dlopen(/Users/Trevor/anaconda3/envs/myenv/lib/python3.8/site-packages/libPyROOT.so, 2): Library not loaded: @rpath/libzstd.1.3.7.dylib  
Referenced from: /Users/Trevor/anaconda3/envs/myenv/lib/libCore.6.20.04.so  
Reason: image not found
