尝试让 cython 运行,在遵循快速入门指南后我遇到了这个问题:
$ ~/midt $ ./setup.py build_ext --inplace
running build_ext
building 'proc' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c proc.c -o build/temp.linux-x86_64-2.7/proc.o
proc.c:2511:16: error: ‘initproc’ redeclared as different kind of symbol
PyMODINIT_FUNC initproc(void); /*proto*/
^
In file included from /usr/include/python2.7/Python.h:80:0,
from proc.c:16:
/usr/include/python2.7/object.h:320:15: note: previous declaration of ‘initproc’ was here
typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
^
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
这是我的版本号和内容:
$ ~/midt $ python --version
Python 2.7.6
$ ~/midt $ cython --version
Cython version 0.23.5
$ ~/midt $ uname -a
Linux xxxxx 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
最佳答案
我认为问题是:
Python 需要调用初始化 C 模块初始化的函数
init<module_name>
(您替换模块名称的位置)。 (Python 3 使用略有不同的形式)。您已将模块命名为
proc
.Cython 因此创建了一个名为
initproc
的函数在导入模块时定义。Python 定义了一个名为
initproc
的 typedef在内部,这与 Cython 生成的initproc
冲突用于初始化您的模块。
解决方案是将您的模块命名为 proc
以外的名称。这不是一个理想的解决方案,但没有太多其他选择。
Python 3 选择不同形式的原因之一 PyInit_<module_name>
众所周知,Python 2 形式会导致一些冲突(请参阅 https://www.python.org/dev/peps/pep-3121/#entry-point-name-conflicts )。
关于python - Cython 构建 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36314266/