FindPython package from pyenv on Windows

Hello.
On Windows 11, we are using pyenv to install different versions of python without headache (until now).
However, when using CMake (3.27) to do:
find_package(Python3 COMPONENTS Interpreter REQUIRED)
It does not find python, although it is in the path. It’s not clear whether it does not find the “executable” at all, or whether it’s just not working. But with pyenv in the path, the path contains a “python” file which is actually a shell script, and a “python.bat” which is a bat script (both in the same folder).
When Python_EXECUTABLE points to python, it fails (because no way to execute a shell script on Windows!). But if I change the FindPython script so that it finds python.bat instead, then it seems to work.
Is this something known ? It is possible/planned to adapt the FindPython for Windows so that it also works with pyenv ? Or is there any way to set variables so that it works somehow ? I tried to set Python_EXECUTABLE variable manually before calling find_package, but it does not work as the find_package script seem to always overwrite the variable.
Any help would be greatly appreciated. Python is a not easy on Windows, with many different installers existing and doing all different things and using different cache folders (Windows Store, User, Local, Chocolatey, etc), with versions incompatible or even corrupting each other, etc. After years of constant struggle, we were finally happy with pyenv and poetry… until we realized that it broke with CMake.
Thanks.
Best regards.

1 Like