[BUG]: CMAKE pybind11 tries to find Python even if it has already been found with find_package() (and finds the wrong version) (Windows 10)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
65370f330ea9349bd9e996028b4cb7adfde37660
Problem description
Hello,
I am using pybind in a project and I am having an error when I try to configure the project using CMake.
I use find_package with the required version of python before adding the pybind directory (as recommanded in the documentation here and I am getting this error when configuring the CMake project :
CMake Error at C:/Program Files/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find PythonInterp: Found unsuitable version "3.10.5", but required is at least "3.12" (found C:/Python/3105/python.exe) Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:598 (_FPHSA_FAILURE_MESSAGE) C:/Program Files/CMake/share/cmake-3.29/Modules/FindPythonInterp.cmake:182 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) pybind11/tools/FindPythonLibsNew.cmake:114 (find_package) pybind11/tools/pybind11Tools.cmake:50 (find_package) pybind11/tools/pybind11Common.cmake:192 (include) pybind11/CMakeLists.txt:237 (include)
And just before the error, Python 3.12 is found :
-- Found Python3: C:/Python/3123/python.exe (found suitable version "3.12.3", minimum required is "3.12") found components: Interpreter Development Development.Module Development.Embed
Reproducible example code
// Cmd
cmake -S . -B build -DPYTHON_VERSION="3.12"
// CMakeLists.txt
...
# Python
find_package(Python3 ${PYTHON_VERSION} COMPONENTS Interpreter Development REQUIRED)
if(NOT ${Python_FOUND})
message(FATAL_ERROR "Python can't be found, exiting CMake")
endif()
set(PYBIND11_PYTHON_VERSION ${PYTHON_VERSION})
set(PYBIND11_FINDPYTHON OFF)
# Pybind
add_subdirectory(pybind11 CONFIG)
...
Is this a regression? Put the last known working version here if it is.
Not a regression
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported CMake stack in pybind11/tools/FindPythonLibsNew.cmake, pybind11/tools/pybind11Tools.cmake, and pybind11/tools/pybind11Common.cmake. Reproduce the configuration from the example CMakeLists.txt on Windows with Python 3.12 and CMake 3.29, then verify that the existing Python selection is respected without the unsuitable-version error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100