Python3 from precompiled versions


_ROOT Version: 6.14.02
Platform: OSX 10.13.6
Compiler: clang 9.1


I have got the latest binary version for OS X. I can import ROOT on python 2, but on python3 there is an error message

~>python3.6
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/roberto/root/lib/ROOT.py", line 24, in <module>
    import cppyy
  File "/Users/roberto/root/lib/cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: dynamic module does not define module export function (PyInit_libPyROOT)

It seems to be “expected”, as many report ROOT to work with python2 out of the box, but not python 3. However, I read many messages “we are working on it”, so I thought I may ask if there is actually a fix already in this recent ROOT release or something has been there for a while and I have just to update some links or path or similar trick to make python3 work. Or am I really lest only with the option to compile from source? (in progress …)

Thanks for the hints and sorry if this is going to be a duplicate. I thought it was good to have a clear cut answer after the subject has appeared in so many threads.
Best
Roberto

I have no idea regarding the state on MacOS, but you can specify the Python version when compiling ROOT. That is, if you are using a precompiled version of ROOT, it will have Py2 bindings. Run cmake and compile ROOT on your own. Instructions here: https://root.cern.ch/building-root#options, look for PYTHON_EXECUTABLE, PYTHON_INCLUDE_DIR, and PYTHON_LIBRARY
If you are compiling >=6.14, see 6.14’s release notes here: https://root.cern.ch/doc/v614/release-notes.html#release-6.1402, i.e. you can use (not yet listed on the options page): cmake -Dpython_version=3 path/to/root-source.

Hi,
I am compiling as we speak but this started yesterday with the “old” PYTHON_EXECUTABLE, PYTHON_INCLUDE_DIR, and PYTHON_LIBRARY variables. Thanks for pointing me to much easier python_version option. Will keep forum posted.

When we distribute ROOT for MacOS, we have to build it against the version of Python that comes with MacOS, and that is Python 2.7. Since that is the only Python that comes with MacOS, I’m afraid that the binaries we distribute will always have to be for the system Python 2.7; we cannot distribute binaries against a version of Python that may not be present in the system, and we don’t want to bundle Python with our binaries. If you want ROOT on MacOS with Python 3.x, just use homebrew to install it with brew install root, and you will get it compiled against Python 3.x by default in that case.

If you compile ROOT from sources, please make sure that you use the same compiler that was used to compile the Python you are using, otherwise you’ll run into problems with incompatible library ABIs.

Hi there! the compilation from source did not give me an installation capable of working with my python3. The error looked like something due to different compilers used for root and python3 I had.
As you suggested I used brew to get both python3 and root and it works … thanks for the tip!

1 Like

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