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

查看:502
本文介绍了尝试编译扩展类型时发生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.

文件内容:

pxd:

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不是类型标识符)。

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天全站免登陆