[Cython] distutils extension pxd problem

Dimitri Tcaciuc dtcaciuc at gmail.com
Thu Feb 2 08:24:43 CET 2012


> Date: Thu, 02 Feb 2012 08:11:16 +0100
> From: Stefan Behnel <stefan_ml at behnel.de>
> To: Core developer mailing list of the Cython compiler
>        <cython-devel at python.org>
> Subject: Re: [Cython] distutils extension pxd problem
> Message-ID: <4F2A3714.7000704 at behnel.de>
> Content-Type: text/plain; charset=UTF-8
>
> Dimitri Tcaciuc, 02.02.2012 01:53:
>> 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 reason you cannot rename "src" to "b"? Because that would fix your
> problem. Cython basically uses the same algorithm for finding package
> content as Python, i.e. it will look inside the package "b" when looking
> for "b.a". And "a.pxd" is not in "b" in your setup.
>
> Stefan
>

This certainly looks like the cleanest solution now. I have some mixed
C++ bits in src/ so I thought to keep compiled/interpreted bits
separate, if possible.


Dimitri.


More information about the cython-devel mailing list