pybind / pybind/pybind11

[BUG]: CMAKE pybind11 tries to find Python even if it has already been found with find_package() (and finds the wrong version) (Windows 10)

Open
#5,100 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Required prerequisites
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.