python - 尝试编译扩展类型时出现 CompileError

标签 python compiler-errors compilation cython

我正在尝试关注此 tutorial使用 pyx、pxd 和 cimport 创建和使用扩展类型。

在终端中编译 Cython 文件时,我收到一个错误,我不知道如何纠正:
cdef class CythonClass:在 pyx 文件中被指示为错误行。

File "/Library/Python/2.7/site-packages/Cython/Build/Dependencies.py", line 1056, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: CythonClass.pyx

我在 MacOS Sierra 上使用 Cython 版本 .25(并且也尝试过其他版本,每个版本都安装了 pip install cython )。 Python 版本是 2.7.10。

按照建议,我安装了 gcc(Xcode 8.2 的命令行工具),但仍然收到错误消息。

文件内容:

像素:
cdef class CythonClass:
    cdef:
        list list1
        dict d1, d2, d3, d4, d5, d6

pyx:
cdef class CythonClass:
    def __init__(self):
        self.list1 = []
        self.d1 = {}
        self.d2 = {}
        self.d3 = {}
        self.d4 = {}
        self.d5 = {}
        self.d6 = {}

setup.py(在终端中由 python setup.py build_ext --inplace 调用):
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize(["CythonClass.pyx"]))

至少目前,我将尝试在不使用 pxd 文件的情况下进行编译,因为已针对扩展类型进行了编译。但是,导入扩展类型的主函数未编译(错误: extTypeName is not a type identifier )。

最佳答案

我在以下位置找到了解决方案:
Cythonize by Command Line
阅读该页面,但更具体地说,请转到以下部分:“使用 cythonize 命令进行编译”。
您创建 .pyd 或 .so 文件:

cython yourmod.pyx
cythonize -a -i yourmod.c
为我工作。

关于python - 尝试编译扩展类型时出现 CompileError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41926482/

相关文章:

clojure - Clojure 是编译的还是解释的?

maven - 从命令行覆盖 Maven 插件版本?

python - 通过谷歌应用程序引擎上的代理获取网址

python - 属性错误 : 'Session' object has no attribute 'save'

python - 在virtualenv python3.4中安装django,在virtualenv中安装linux os

c# - 使用未分配的局部变量 'a'

C++ 从函数返回一个局部变量作为引用

android - 使用 ffmpeg for Android 编译 x265 并接收错误

python - Flake8 错误 : E712 comparison to True should be 'if cond is True:' or 'if cond:'

python - 我想分割一个节点的文本,然后将它们放入独立的元素中