1
我在一臺較舊的計算機上,我試圖用Cython加速我編寫的一些python代碼,但是即使是最簡單的腳本,我也無法使用Cython。Cython編譯器錯誤
這裏是Python代碼,我試圖通過用Cython運行,並從我的知識應該工作:
def hw():
print "Hello World"
if __name__ == "__main__":
hw()
這裏是從我的終端輸出:
C:\PyProjects\_cython>python hw.py
Hello World
C:\PyProjects\_cython>cython hw.py
C:\PyProjects\_cython>gcc hw.c
In file included from hw.c:4:
Python.h:8:22: error: pyconfig.h: No such file or directory
hw.c:457: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx_
PyInt_AsUnsignedLongLong'
hw.c:461: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx_
PyInt_AsLongLong'
hw.c:465: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx_
PyInt_AsSignedLongLong'
hw.c: In function '__Pyx_PyUnicode_Equals':
hw.c:826: error: 'Py_UNICODE' undeclared (first use in this function)
hw.c:826: error: (Each undeclared identifier is reported only once
hw.c:826: error: for each function it appears in.)
hw.c:826: error: expected ';' before 'ch1'
hw.c:827: error: expected ';' before 'ch2'
hw.c:828: error: 'ch1' undeclared (first use in this function)
hw.c:828: error: 'ch2' undeclared (first use in this function)
hw.c: At top level:
hw.c:1204: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx
_PyInt_AsUnsignedLongLong'
hw.c:1274: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx
_PyInt_AsLongLong'
hw.c:1344: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx
_PyInt_AsSignedLongLong'
hw.c: In function '__Pyx_InitStrings':
hw.c:1564: warning: assignment makes pointer from integer without a cast
hw.c: In function '__Pyx_PyInt_AsSize_t':
hw.c:1669: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'val'
hw.c:1669: error: 'val' undeclared (first use in this function)
hw.c:1670: error: expected ')' before 'LONG_LONG'
hw.c:1672: error: expected ')' before 'LONG_LONG'
我在windows 7 64bit使用32bit python 2.7
您的'gcc'命令缺少include目錄和其他選項。 – 2012-07-31 03:53:44
使Basile的評論更具體。確保Python.h可以被gcc包括在內以作爲開始。 – Endophage 2012-07-31 03:54:40
好吧,我用「gcc hw.c -IC:\ Python27 \ include」,結果如下:http://codepad.org/7uqvY7ui 它仍然失敗並且拋出一個錯誤 – 2012-07-31 03:59:03