Skip to content

fix(cmake): find missing Python development components#6116

Draft
henryiii wants to merge 1 commit into
pybind:masterfrom
henryiii:fix/cmake-find-missing-dev-components
Draft

fix(cmake): find missing Python development components#6116
henryiii wants to merge 1 commit into
pybind:masterfrom
henryiii:fix/cmake-find-missing-dev-components

Conversation

@henryiii

@henryiii henryiii commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

I think this is both helpful and there are issues with it. Will investigate. See #6112.

🤖 AI text below 🤖

Description

pybind11NewTools.cmake skipped its Python discovery if Python_FOUND or Python3_FOUND was set. A parent project that did find_package(Python COMPONENTS Interpreter) (frequently out of the user's control) thus left pybind11 without the development components, which caused:

  • pybind11_add_module to fail with Unknown CMake command "python_add_library" or target Python::Module is not defined,
  • pybind11::embed to silently miss the link to Python::Python.

pybind11 now asks FindPython for the missing development components instead of skipping the find. It keeps the name (Python or Python3) and the interpreter that the parent project selected, and it makes the new targets global in submodule mode. If the parent project already supplied the development components, the behavior does not change.

The subdirectory_embed CMake build test now does a partial find_package(Python COMPONENTS Interpreter) first, which fails without this fix.

Supersedes #5814, which removed the guard completely.

Fixes #5813
Fixes #5472
Fixes #6063

Suggested changelog entry:

  • Fixed CMake so that a find_package(Python) from a parent project without the development components no longer breaks pybind11_add_module or the pybind11::embed link to Python.

https://claude.ai/code/session_013JABmnjt9oAh29p1pytAB3

If a parent project called find_package(Python) without the development
components, pybind11 skipped its own find, so pybind11_add_module failed
and pybind11::embed did not link to Python::Python. Ask FindPython for
the missing components instead, keeping the interpreter already selected.

Assisted-by: ClaudeCode:claude-opus-5
Claude-Session: https://claude.ai/code/session_013JABmnjt9oAh29p1pytAB3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant