Where are Python headers included in MacOS Monterey arm64

I am currently struggling to find the python headers on my system and can’t include them therefore into a C++ application

this is my cmake file –>

cmake_minimum_required(VERSION 3.14)

project(ondoki-desktop VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_TOOLCHAIN_FILE /Users/ahoehne/repos/vcpkg/scripts/buildsystems/vcpkg.cmake)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)



set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(${PYTHON_INCLUDE_DIRS})

find_package(Python3 COMPONENTS Interpreter REQUIRED)





if(DEFINED ENV{VIRTUAL_ENV} OR DEFINED ENV{CONDA_PREFIX})
  set(_pip_args)
else()
  set(_pip_args "--user")
endif()

include(ExternalProject)
ExternalProject_Add(ondoki-daemon
  GIT_REPOSITORY    "https://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@github.com/ondoki-org/ondoki-daemon.git"
  GIT_TAG           develop
  SOURCE_DIR        "${PROJECT_SOURCE_DIR}/ondoki-daemon"

  CONFIGURE_COMMAND ""
  BUILD_COMMAND     ""
  INSTALL_COMMAND   ""
  TEST_COMMAND      ""

)

execute_process(COMMAND ${Python3_EXECUTABLE} -m pip install -r ${PROJECT_SOURCE_DIR}/ondoki-daemon/requirements.txt)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED)
find_package(ZeroMQ CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(cppzmq CONFIG REQUIRED)
find_package(protobuf CONFIG REQUIRED)
find_package( Boost REQUIRED COMPONENTS  )
find_package (Boost COMPONENTS filesystem regex REQUIRED)
find_package(msgpack CONFIG REQUIRED)

find_package(pybind11 CONFIG REQUIRED)




set(PROJECT_SOURCES
        main.cpp
        qml.qrc
        images.qrc
        python.qrc
        zmqbridge.cpp
        zmqbridge.h
        zmqworker.h
        zmqworker.cpp
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(ondoki-desktop
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET ondoki-desktop APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(ondoki-desktop SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(ondoki-desktop
          ${PROJECT_SOURCES}
        )
    endif()
endif()

target_compile_definitions(ondoki-desktop
  PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(ondoki-desktop
  PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick
  protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite libzmq
          libzmq-static  nlohmann_json nlohmann_json::nlohmann_json
          cppzmq cppzmq-static ${Boost_LIBRARIES} ¢{PYTHON_LIBRARIES}
          msgpackc msgpackc-cxx pybind11::lto pybind11::embed pybind11::module

  )

set_target_properties(ondoki-desktop PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_import_qml_plugins(ondoki-desktop)
    qt_finalize_executable(ondoki-desktop)
endif()


The Error message for including #include <pybind11/embed.h> is common.h Python.h not found

locate python.h results in

/Applications/CLion.app/Contents/plugins/python-ce/helpers/pydev/pydevd_attach_to_process/common/python.h
/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd_attach_to_process/common/python.h
/opt/homebrew/Cellar/boost/1.76.0/include/boost/mpi/python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/parameter/python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/arg_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/arg_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/arg_to_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/obj_mgr_arg_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/return_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/shared_ptr_from_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/converter/shared_ptr_to_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/detail/wrap_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python/register_ptr_to_python.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/python.hpp

/usr/local/include has no Python.h as has /opt/homebrew/include

a "which python3" results in /opt/homebrew/bin/python3

and my cmake parameters are the following

-GNinja
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake
-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}
-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}
-DCMAKE_TOOLCHAIN_FILE=/Users/ahoehne/repos/vcpkg/scripts/buildsystems/vcpkg.cmake
%{CMAKE_OSX_ARCHITECTURES:DefaultFlag}

Thank you for any help or hints into the right direction.

***EDIT ***

if i include

include_directories(/opt/homebrew/Frameworks/Python.framework/Headers)

at least he seems to find the header

but results in a "expected member name or ";" after declaration specifiers –> Following the object.h file I see

typedef struct{
    int slot;    /* slot id, see below */
    void *pfunc; /* function pointer */
} PyType_Slot;

typedef struct{
    const char* name;
    int basicsize;
    int itemsize;
    unsigned int flags;
    PyType_Slot *slots; /* terminated by slot==0. */
} PyType_Spec;

on the error code line …if I remove PyType_Slot *slots; the program compiles but I highly doubt that this is a bug and rather a problem on my side

>Solution :

It seems to me that the first problem is with the order of these lines:

include_directories(${PYTHON_INCLUDE_DIRS})
find_package(Python3 COMPONENTS Interpreter REQUIRED)

So you refer to an unknown yet PYTHON_INCLUDE_DIRS variable.

The second problem is the variable name itself. You are searching for Python3 package so to me the variable name should be Python3_INCLUDE_DIRS as per the FindPython3 doc

The 3rd problem is that you are searching for Interpreter only, so the headers will not be found anyway.

Summarising, please check if something like the following works:

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
include_directories(${Python3_INCLUDE_DIRS})

Leave a Reply