gpt4 book ai didi

python - Cython 构建 python 脚本

转载 作者:太空宇宙 更新时间:2023-11-04 03:15:53 27 4
gpt4 key购买 nike

尝试让 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

最佳答案

我认为问题是:

  1. Python 要求初始化一个 C 模块初始化的函数被调用 init<module_name> (你替换你的模块名称的地方)。 (Python 3 使用稍微不同的形式)。

  2. 您已将您的模块命名为 proc .

  3. Cython 因此创建了一个名为 initproc 的函数在导入模块时定义。

  4. Python 定义了一个名为 initproc 的类型定义。在内部,这与生成的 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/

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