[Cython] cimport inside a package

Robert Bradshaw robertwb at math.washington.edu
Thu Apr 3 07:13:05 CEST 2008


I think the problem is that it's getting confused between the names  
"foo" and "zap.foo." I'm not sure, however, what the correct solution  
to this is, other than giving the names via setup.py, but perhaps  
someone more familiar with distutils and/or compiling extensions by  
hand would have a better idea what's going on.

- Robert

On Mar 27, 2008, at 1:28 PM, Simon Burton wrote:
>
>
> I have a Makefile ( the -I. doesn't seem to help):
>
>
> bar.so: bar.o
>         gcc $(CFLAGS) -shared bar.o -o bar.so
>
> bar.o: bar.c
>         gcc $(CFLAGS) -c bar.c -I/usr/include/python2.5
>
> bar.c: bar.pyx
>         cython -I. bar.pyx
>
>
>
> foo.so: foo.o
>         gcc $(CFLAGS) -shared foo.o -o foo.so
>
> foo.o: foo.c
>         gcc $(CFLAGS) -c foo.c -I/usr/include/python2.5
>
> foo.c: foo.pyx
>         cython -I. foo.pyx
>
>
>
>
> On Thu, 27 Mar 2008 13:25:45 -0700
> Robert Bradshaw <robertwb at math.washington.edu> wrote:
>
>> What does your setup.py look like?
>>
>> On Mar 27, 2008, at 1:17 PM, Simon Burton wrote:
>>
>>> == foo.pxd ==
>>>
>>>
>>> cdef int foo()
>>>
>>>
>>> == foo.pyx ==
>>>
>>> cdef int foo():
>>>     print "hi foo"
>>>     return 9
>>>
>>>
>>> == bar.pyx ==
>>>
>>> cimport foo
>>>
>>> def bar():
>>>     print foo.foo()
>>>
>>> =============
>>>
>>> All good so far.
>>>
>>> If I put the above in a regular python package called zap,
>>> and then (from outside of the zap package):
>>>
>>> $ python
>>> Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12)
>>> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
>>> Type "help", "copyright", "credits" or "license" for more  
>>> information.
>>>>>> from zap import bar
>>> Traceback (most recent call last):
>>>   File "<stdin>", line 1, in <module>
>>>   File "bar.pyx", line 2, in bar
>>> ImportError: No module named foo
>>>>>>
>>>
>>> The C code in bar.c is trying to import module bar.
>>> What is the correct cimport invocation in bar.pyx ?
>>> I tried some obvious permutations ("from zap cimport bar"), but
>>> nothing got past
>>> the cython compiler.
>>>
>>> Simon.
>>>
>>> _______________________________________________
>>> Cython-dev mailing list
>>> Cython-dev at codespeak.net
>>> http://codespeak.net/mailman/listinfo/cython-dev
>>
> _______________________________________________
> Cython-dev mailing list
> Cython-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev



More information about the Cython-dev mailing list