ballade4op52
ballade4op52

Reputation: 2267

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

Upvotes: 5

Views: 3841

Answers (1)

user3644627
user3644627

Reputation: 107

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.

Upvotes: 0

Related Questions