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)