尝试编译扩展类型时出现 CompileError [英] CompileError when attempting to compile extension type

查看:52
本文介绍了尝试编译扩展类型时出现 CompileError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照此教程进行操作使用 pyx、pxd 和 cimport 创建和使用扩展类型.

I’m trying to follow this tutorial on using pyx, pxd, and cimport to create and use extension types.

在终端编译 Cython 文件时,我收到一个错误,我不知道如何纠正:

When compiling the Cython file in terminal, I am getting an error that I don’t know how to correct for:

cdef class CythonClass: pyx文件中的错误行表示.

cdef class CythonClass: in the pyx file is indicated as the line of error.

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.

I am using Cython version .25 (and have tried other versions as well, each installed with pip install cython) on MacOS Sierra. Python version is 2.7.10.

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

As suggested, I installed gcc (Command Line Tools for Xcode 8.2), but am still receiving the error.

文件内容:

像素:

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 调用):

setup.py (invoked by python setup.py build_ext --inplace in terminal):

from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize(["CythonClass.pyx"]))

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

At least presently, I'll attempt to compile without using pxd files, since the compilation went through for the extension types. However, the main function that imports the extension types is not compiling (with error: extTypeName is not a type identifier).

推荐答案

我在以下位置找到了解决方案:通过命令行进行 Cythonize

I found a solution at: Cythonize by Command Line

阅读该页面,但更具体地转到以下部分:使用 cythonize 命令进行编译".

Read the page but more specifically go to the section: "Compiling with the cythonize command".

您创建 .pyd 或 .so 文件:

You create the .pyd or .so file:

cython yourmod.pyx
cythonize -a -i yourmod.c

为我工作.

这篇关于尝试编译扩展类型时出现 CompileError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆