How to properly install PyROOT for Python 3?

I am attempting to install the Python3 bindings for ROOT, but always seem to end up with Python2 bindings. I have used the CMake flags -Dpython=ON and -Dpython3=ON. I have both python2 and python3 installed and the python command defaults to the python 2 version. From a posting by @Graipher I have a suspicion that it has to do with what the default python version is (he has the opposite issue). Do I need to change where the default points before configuring to get the correct version?

Also mentioned here:

And some useful information in a bug report here:
https://sft.its.cern.ch/jira/browse/ROOT-8260

The error message recieved when trying to start in python3 is:

$ python3.6
Python 3.6.2 (default, Sep 21 2017, 00:54:38) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] 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 "/opt/root/6.10.06-py3/lib/ROOT.py", line 24, in <module>
    import cppyy
  File "/opt/root/6.10.06-py3/lib/cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: dynamic module does not define module export function (PyInit_libPyROOT)

Thanks

1 Like

I went ahead and tested this changing python to point to python3, rebuilt and I get the python3 bindings. Using this information and the info from @Graipher it seems the the -Dpython3 flag is ignored and the version is picked from what the alias python points to.

1 Like

You can use -DPYTHON_EXECUTABLE=/path/to/desired/python without aliasing anything.

Ahh, useful. So the solution is to ignore the non-working python3 flag and use the PYTHON_EXECUTABLE flag.

Opened a bug report indicating that the python3 flag seems to be ignored: https://sft.its.cern.ch/jira/browse/ROOT-9033

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