Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

python - CompileError when attempting to compile extension type

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

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

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

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.

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

File contents:

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 (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"]))

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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found a solution at: Cythonize by Command Line

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

You create the .pyd or .so file:

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

Worked for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...