Hi CMake,
I am trying to use CMake (3.25) on Windows with Visual Studio (2022). I need to include Python3 in my project. When I try to build the project it complains that it cannot find “Python.h”.
Both CMake and Python3 have been added to the system path.
I have the following in my “CMakeLists.txt”:
find_package (Python3 COMPONENTS Interpreter Development)
if (${Python3_FOUND})
message ("Found Python3 " ${Python3_VERSION})
message ("Found Python3 in " ${Python3_EXECUTABLE})
else()
message (“Couldn’t find Python3!”)
endif()if (${Python3_INCLUDE_DIR})
message ("Found Python3 include directories: ")
else()
message (“Couldn’t find Python3 include directories!”)
endif()if (${Python3_Interpreter_FOUND})
message (“Found Python3 Interpreter”)
else()
message (“Couldn’t find Python3 Interpreter!”)
endif()if (${Python3_Development_FOUND})
message (“Found Python3 Development”)
else()
message (“Couldn’t find Python3 Development!”)
endif()
And when CMake generation runs, I get the following:
1> [CMake] Looking for Python3…
1> [CMake] Found Python3 3.11.1
1> [CMake] Found Python3 in C:/Tools/Python311_64/python.exe
1> [CMake] Couldn’t find Python3 include directories!
1> [CMake] Found Python3 Interpreter
1> [CMake] Found Python3 Development
1> [CMake] – Configuring done
1> [CMake] – Generating done
1> [CMake] – Build files have been written to: C:/Users/het/source/python_test/Python_in_CPP_CMake/out/build/x64-release
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.
As far as I can see, everything looks fine, except for “Couldn’t find Python3 include directories!”! Which I assume also is the reason why it fails to build? Should the “Python3_INCLUDE_DIRS” variable not be automatically populated when Python3 is successfully located?
Am I doing something wrong? I hope you can help me make my project build.
Thanks.