[Cython] distutils extension pxd problem

Dimitri Tcaciuc dtcaciuc at gmail.com
Thu Feb 2 01:53:02 CET 2012


Hey everyone,

I bumped into an issue where my .pyx file doesn't see its matching
.pxd file. Here's a build test to show the problem If I change my
target package from `b.a` to just `a`, it works as expected. Running
`cython src/a.pyx` works as expected as well, but not the Extension.

----

PYTHON setup.py build_ext --inplace
PYTHON -c "from b import a"

######## setup.py ########

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [
    Extension("b.a", ["src/a.pyx"])
]

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = ext_modules
)

######## b/__init__.py ########

######## src/a.pxd ########

cdef class X:
    cdef object foo

######## src/a.pyx ########

cdef class X:

    def __cinit__(self):
        self.foo = 1

x = X()

----

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "a.pyx", line 7, in init b.a (src/a.c:793)
  File "a.pyx", line 5, in b.a.X.__cinit__ (src/a.c:488)
AttributeError: 'b.a.X' object has no attribute 'foo'

----

Any idea what's going on here?

Thanks,


Dimitri.


More information about the cython-devel mailing list