問題描述
我正在嘗試在 CentOS 機(jī)器上編譯用 C 編寫的 Python 擴(kuò)展.我得到了
I am trying to compile a Python extension written in C on a CentOS machine. I am getting
error: Python.h: No such file or directory
它在 ubuntu 上運(yùn)行良好,我使用 apt-get 安裝了 python-dev.
It works fine on ubuntu, where I have python-dev installed using apt-get.
我嘗試使用安裝 python-devel
I tried installing python-devel using
yum install python-devel
但它已經(jīng)安裝了.如何解決此錯誤?
but it is already installed. How do I fix this error?
推薦答案
在我的系統(tǒng)上,Python.h
頭文件位于路徑 /usr/include/python2.6/代碼>.由于預(yù)處理器默認(rèn)不搜索此路徑,因此您必須將其添加到要搜索的路徑列表中.這是通過編譯器的
-I
選項完成的,如下所示:
On my system the Python.h
header file is in the path /usr/include/python2.6/
. As this path is not searched by the pre-processor by default, you have to add it to the list of paths to search. This is done with the -I
option to the compiler, like this:
$ gcc -I/usr/include/python2.6 source.c -o program
將上面的路徑更改為系統(tǒng)上的實際路徑.您可以使用 find
命令中的建議找到它locate
命令(如果已安裝)的注釋.
Change the path above to the actual path on your system. You can find it either with the find
command as proposed in a comment, of with the locate
command if it's installed.
這篇關(guān)于在 CentOS 上找不到 Python.h 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!