gpt4 book ai didi

python - Cython 编译器错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:12:43 24 4
gpt4 key购买 nike

我在一台旧电脑上,我正在尝试使用 Cython 来加速我编写的一些 python 代码,但是我无法让 Cython 使用即使是最简单的脚本。

这是我试图通过 Cython 运行的 python 代码,据我所知应该可以工作:

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 64 位上使用 32 位 python 2.7

最佳答案

看看 documentation .根据我的经验,最简单的方法是使用 distutils,因为它知道传递给编译器所需的所有信息(例如, header 的位置、重要的库、编译器选项以创建合适的共享对象等)而且,毕竟,编写一个 setup.py 文件并不十分困难。如果您不想安装该库,只需执行 python setup.py build 并将共享对象复制到您想要的任何目录(尽管您可能需要在 build 目录以便找到它)。

关于python - Cython 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11732805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com