Finding pyenv python package using CMake

Hi, We are using pyenv to manage python versions in a project that mixes python and C++ code. We have one item whose CMakeLists file needs to find the python package which is specified by the project pyenv version. Right now it finds the system version instead. What is the cmake command to find the python interpreter for the version specified by pyenv? Ubuntu 18.04, cmake version 3.10 (or newer is ok), the python pyenv version is 3.7.3.

I suspect that specifying the search strategy and a ROOT variable based on the pyenv information CMake has access to. See the FindPython3 docs for details and the variables that matter.

A bit late to the party, but I ran into issues with CMake + pyenv on Windows today.
Based on the comment above, I added a few lines before calling find_package to set the ROOT_DIR, which solved the issue for me.

# Before looking for Python, check if pyenv is available
if(WIN32)
  find_program(PYENV_EXE NAMES pyenv.bat pyenv)

  if(PYENV_EXE)
    execute_process(
      COMMAND "${PYENV_EXE}" which python3
      OUTPUT_VARIABLE PYENV_PYTHON
      OUTPUT_STRIP_TRAILING_WHITESPACE
    )

    if(PYENV_PYTHON AND EXISTS "${PYENV_PYTHON}")
      get_filename_component(Python3_ROOT_DIR "${PYENV_PYTHON}" DIRECTORY)
      set(Python3_ROOT_DIR "${Python3_ROOT_DIR}" CACHE PATH "Root dir for Python3 from pyenv")
      message(STATUS "Used pyenv to find Python 3 in: ${Python3_ROOT_DIR}")
    endif()
  endif()
endif()

find_package(Python3 REQUIRED)