Compiling ROOT with both python2 and python3 bindings

Hi all,

I have a set of scripts that I use to update ROOT on my local machine (usually the latest version of Fedora, currently 25)
They are set up such that I can specify whether to build with gcc or clang, and can also specify which python version to build bindings for.
I have done this and built against both python versions, and can specify whether to use one or the other, but if I setup the version I compiled against python2, the python3 bindings are not there, and vice versa (as expected)

So I then thought I’d be clever in setting up my python bindings, by creating soft links from the generated files into the appropriate site-packages, but this was still not correct. I suspect that I’m missing a library path somewhere, as the complaint is always with importing ROOT into the python version that was not “set up” in the script that sources the ROOT setup.

However in the end, I would like to be able to have it set up that I build bindings for both python2 (2.7) and python3 (3.5), rather than duplicating the build, and having the bindings work for either python2 or python3.

I know this must be possible as the version of ROOT that ships with Fedora has both of these bindings available (and working), however I can’t seem to dig up the build process that Fedora uses (yes, I could take the version of ROOT that Fedora ships, but I don’t want to be handcuffed if version migration within the distribution doesn’t keep up with ROOT upstream).

If anyone has any ideas or suggestions, I’d appreciate them.

Thanks for your time!

Cheers,

Jared

1 Like

Hi,

I’m not aware of such an option, but maybe @mato could have an idea…

Cheers, Bertrand.

Hi Jared,

As far as I can tell, the build system only lets you choose one of the options (either python2 or python3).
See, for instance, https://sft.its.cern.ch/jira/browse/ROOT-8260.

There is work in progress to install the python bindings for more than one version of python at the same time, however.
Hopefully that will be possible in the near future.

Best,
—Guilherme

As mentioned by @amadio currently we can build the python bindings with python2 or python3 but not both at the same time. If it is true that Fedora does it, it would be nice to know how it manages it.

Hi all,

@mato, I’ve asked at the Fedora help if someone could point me to the build scripts that are being used, and if I get an answer, I’ll share that info.
@amadio, I did finally manage to get the libraries to load simultaneously, after building them separately (I had forgotten to unset PYTHONPATH set by the ROOT setup script). Now I am able to import either version of the bindings by doing:

I’ve set up the following version of ROOT using the thisroot.sh script:

which root
root='root -l'
        /opt/root/v6-08-00-patches/clang/python3/bin/root

Loading in python2.7 works

Python 2.7.13 (default, Jan 12 2017, 17:59:37) 
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT as r
>>> 

Loading in python3.5 also works

Python 3.5.3 (default, Mar 21 2017, 17:21:33) 
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT as r
>>> 

I suppose the only optimization to my workflow would be to have the two sets of bindings built simultaneously, which I hope to get figured out (that and waiting for ROOT to be able to be built with the non-special ROOT versions of clang/llvm, which I understand is “close” for llvm but reasonably far for clang.)

I’m attaching the script I have used to set this up, with the caveat that it works for me on Fedora, with the directory structure there, but would likely have to be adapted to other systems.

Cheers,

Jared

setuproot.txt (5.2 KB)

Someone on the Fedora help list pointed me to the spec file that is used to build ROOT

https://src.fedoraproject.org/cgit/rpms/root.git/tree/root.spec

It shows that they basically set up the build, make the targets, then move the python2 files to a new directory, rebuild the python bindings with the python3 option set, and put these output files in another separate directory.
Not sure if it’s simple to set up with cmake, but it should be quite simple to do with a few lines of a script

1 Like

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