Python.h: No such file or directory Python.h: No such file or directory python python

Python.h: No such file or directory


In your CMakeLists.txt, try adding the following:

find_package(PythonLibs REQUIRED)include_directories(${PYTHON_INCLUDE_DIRS})target_link_libraries(<your exe or lib> ${PYTHON_LIBRARIES})

For details of the commands, run:

cmake --help-module FindPythonLibscmake --help-command find_packagecmake --help-command include_directoriescmake --help-command target_link_libraries


sudo apt-get install pythonX.X-dev

For example for 3.8

sudo apt-get install python3.8-dev

Thank you Cristianjs19 for the comment.

Original Answer:

sudo apt-get install python2.7-dev

worked for me on a "Python.h: No such file or directory" issue


You want to include the following on the compile line:

`python-config --cflags`

and this on the link line:

`python-config --ldflags`