Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 compatible version of ROOT with CMSSW #6

Open
lcorcodilos opened this issue Oct 9, 2020 · 0 comments
Open

Python3 compatible version of ROOT with CMSSW #6

lcorcodilos opened this issue Oct 9, 2020 · 0 comments

Comments

@lcorcodilos
Copy link
Owner

lcorcodilos commented Oct 9, 2020

There's no good resource (that I've found) that explains which CMSSW versions have which python and ROOT versions. They almost always come with some version of python 2.7 and python 3.x but ROOT (up until v6.22) can only be compiled for one version of python at a time - and in CMSSW it's almost always python 2.7.

This is dumb. We are 8 months past EOL of python 2.7 (1/1/2020). The trick to get a python3 version of ROOT (on LPC at least) is to just source the version of root you want after your cmsenv.

source /cvmfs/cms.cern.ch/slc7_amd64_gcc820/lcg/root/6.22.00/bin/thisroot.sh

The problem is that v6.22 is built for python 3.8 compatibility and not 3.6 (it also has python2.7 support - having both is new to v6.22). So we also need to be in a CMSSW with python 3.8. I just grabbed the latest possible CMSSW to find this (without getting into the _pre versions). Here's the full setup.

cmsrel CMSSW_11_4_1 # has python 3.8 (root version we grab will be compiled for python3.8 but not python3.6)
cd CMSSW_11_4_1/src
cmsenv
source /cvmfs/cms.cern.ch/slc7_amd64_gcc820/lcg/root/6.22.00/bin/thisroot.sh # compiled for python2.7 and python3.8 (not for python3.6 which is why we need CMSSW_11_4_1)
python3 -c "import ROOT" # test python3 - should return nothing
python2.7 -c "import ROOT" # test python2.7 - should return nothing

Of course, this means that you need to source your root version manually after cmsenv. My recommendation around this is to do one of two things:

  1. Setup an alias in your .bashrc like alias cmsenv_py3='cmsenv; source /cvmfs/cms.cern.ch/slc7_amd64_gcc820/lcg/root/6.22.00/bin/thisroot.sh'. Then use this alias instead of cmsenv.
  2. Setup a python virtualenv and modify the activate script to run source /cvmfs/cms.cern.ch/slc7_amd64_gcc820/lcg/root/6.22.00/bin/thisroot.sh at the end.
cmsenv
python3 -m virtualenv pyroot3
echo "\nsource /cvmfs/cms.cern.ch/slc7_amd64_gcc820/lcg/root/6.22.00/bin/thisroot.sh" > pyroot3/bin/activate
source pyroot3/bin/activate

With this option, you'll need to remember to activate the virtualenv every time after you cmsenv but in general, virtualenvs are good to use so you can install other python packages via pip.

  1. (a) If you wanna be really cool, also modify the deactivate function in pyroot3/bin/activate so that it resets the root version to the original for CMSSW_11_4_1. I'm not gonna write it out because you could easily also run cmsenv to reset it.

  2. Combine (1) and (2) so that the alias also does the virtualenv activating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant