Python.h: No such file or directory

别来无恙 提交于 2019-11-29 22:20:17

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 FindPythonLibs
cmake --help-command find_package
cmake --help-command include_directories
cmake --help-command target_link_libraries
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`

Most likely Python.h is not in your build systems' include path. You can find out where your Python.h is by running

dpkg -L python-dev | grep Python.h

This will also verify that the python-dev package actually installed a Python.h.

I don't have a kdevelop here, but most IDEs have a setting somewhere where you can specify the include path used by the build system, and you should be able to add the path where Python.h lies there.

EDIT:

As Nikolai implied, you will also need to add the correct library path for the linking stage. (Output of python-config --ldflags).

I assume that it is already installed. Find the path with:

find / -iname python.h

and when you have done so, when compiling add

-I python_h_path
chhotu sardar

For Linux Ubuntu Putty Users try this:

sudo apt-get update
sudo apt-get install python-dev

then compile it

gcc -o check xyz.c -I/usr/include/python2.7/ -lpython2.7

then run it

./check 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!