CMAKE python version mismatch?

Dear Experrs,
I am using ROOT 6.23/01 form cmvfs dev3/nightlies slot:

source /cvmfs/sft.cern.ch/lcg/views/dev3/latest/x86_64-centos7-gcc9-opt/setup.sh

and then I am using a kind of test CMAKE project with CMakeLists.txt file

project (MyProject) 
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

find_package(ROOT 6 CONFIG REQUIRED )

message ( "----> ROOT   version   : " ${ROOT_VERSION} )

# =============================================================================
## Locate proper Python/PythonLibs 
find_program(ROOT_CONFIG_EXECUTABLE NAMES root-config)
message ( "ROOT_CONFIG_EXECUTABLE " ${ROOT_CONFIG_EXECUTABLE} ) 

execute_process( COMMAND "${ROOT_CONFIG_EXECUTABLE}" --python2-version
                 OUTPUT_VARIABLE PY2VERSION_ROOT
                 OUTPUT_STRIP_TRAILING_WHITESPACE )

execute_process( COMMAND "${ROOT_CONFIG_EXECUTABLE}" --python3-version
                 OUTPUT_VARIABLE PY3VERSION_ROOT
                 OUTPUT_STRIP_TRAILING_WHITESPACE )

message ('PY2VERSION_ROOT:' ${PY2VERSION_ROOT} )
message ('PY3VERSION_ROOT:' ${PY3VERSION_ROOT} )

if     (PY2VERSION_ROOT)
  find_package(Python2 ${PY2VERSION_ROOT} COMPONENTS Interpreter Development NumPy)
  set(Python_VERSION ${Python2_VERSION}  )
  if  (Python2_FOUND)
    message ( "Python version: " ${Python2_VERSION} )
  else()
    message ( "Python2 is NOT FOUND!" ) 
  endif()
elseif (PY3VERSION_ROOT)
  find_package(Python3 ${PY3VERSION_ROOT} COMPONENTS Interpreter Development NumPy)
  set(Python_VERSION ${Python3_VERSION}  )
  if  (Python3_FOUND)
    message ( "Python version: " ${Python3_VERSION} )
  else()
    message ( "Python3 is NOT FOUND!" ) 
  endif()  
endif () 

and surprizingly I see the following message:

----> ROOT   version   : 6.23.01
ROOT_CONFIG_EXECUTABLE /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3/Wed/x86_64-centos7-gcc9-opt/bin/root-config
'PY2VERSION_ROOT:'2.7.16
'PY3VERSION_ROOT:'
-- Could NOT find Python2: Found unsuitable version "2.7.13", but required is at least "2.7.16" (found /cvmfs/lhcb.cern.ch/lib/var/lib/LbEnv/941/stable/x86_64-centos7/bin/python2.7)
Python2 is NOT FOUND!
-- Configuring done

You see CMAKE picks up python “LHCb” - and not from LCG!
How can I force it to find and use LCG version?

or interactive stuff it picks up the correct version from LCG:

>where python
/cvmfs/sft-nightlies.cern.ch/lcg/views/dev3/Tue/x86_64-centos7-gcc9-opt/bin/python
/cvmfs/lhcb.cern.ch/lib/var/lib/LbEnv/941/stable/x86_64-centos7/bin/python
/usr/bin/python

What is correct way in for CMAKE project to access correct ROOT+python ?


Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.23/01
_Platform: Centos7, LCG-nightlies from cvmfs
_Compiler: gcc9


Hello,

One way would be to define Python2_EXECUTABLE=path_to_lcg_python2 (or Python2_ROOT_DIR) to give a hint to CMake when it runs find_package(Python2, ....

https://cmake.org/cmake/help/git-stage/module/FindPython2.html

@oshadura can perhaps comment.

@etejedor thanks for your reply! It is definitely a right way to go!

In fact, I was thinking about how it could happen…

As I understood that @ibelyaev probably wanted to have a chance to configure his project without specifying PYTHON_EXECUTABLE or Python2_EXECUTABLE, but relying on the Cmake routine.

@etejedor actually I wanted to ask you if it important for PyROOT to use precisely 2.7.16 and not 2.7.13 (can we emit patch version)?

P.S. @ibelyaev can you try please with exact version

find_package(Python2 ${PY2VERSION_ROOT} EXACT COMPONENTS Interpreter Development NumPy)?

Dear Oksana,

I’ve added EXACT, but nothing changes…

Dear Oksana,

yes, I wanted to get as much as possible from CMAKE.
(Might be a bit naively) I think that it is the only way to guarantee
the consistency and to avoid the version conflicts.

Btw - is my treatment of py2/py3 versions for the dependent project has a sense?
Likely there are some recommended examples (I’ve failed to find).

… and it is a bit puzzling why CMAKE does not find (correct version of) python from LCG (especially in the case where the correct executable is picked outside CMAKE) and picks up incorrect version that is not the first in the path…

@etejedor actually I wanted to ask you if it important for PyROOT to use precisely 2.7.16 and not 2.7.13 (can we emit patch version)?

2.7.13 should be totally fine for PyROOT, so using the LHCb Python (even if the subminor version is different) should be ok.

As for why CMake finds the LHCb Python instead of the LCG one, I don’t know.

It totally makes sense, but actually you are the first asking such question, so I believe maybe you are the first trying it in such a way.

thank you, Oksana!

1 Like

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