relative cimport

30 views
Skip to first unread message

Christoph Groth

unread,
Sep 27, 2012, 11:35:53 AM9/27/12
to cython...@googlegroups.com
Hi,

Relative imports work in Cython now, but relative cimports don't seem to
be working. Is my impression correct?

Specifically, we have right now:

from kwant.graph.defs cimport gint
from kwant.graph.defs import gint_dtype

I'd like to stop using the explicit name (=kwant) of the package
explicitly so that several versions of the package can be installed and
used simultaneously under different names. If cimport would be like
import, we could do

from .graph.defs cimport gint
from .graph.defs import gint_dtype

But this leads to the error message

****************************************************************
from .graph.defs cimport gint
^
------------------------------------------------------------

kwant/_system.pyx:8:0: 'graph.defs.pxd' not found
****************************************************************

The directory kwant/graph/ that contains defs.pxd and defs.h has been
added to the include path of Cython.

What actually does work is

from defs cimport gint
from .graph.defs import gint_dtype

But what if we have several defs.pxd in the various subpackages of our
package?

Is it possible to resolve this issue elegantly with current Cython?

thanks,
Christoph

Christoph Groth

unread,
Sep 28, 2012, 9:13:47 AM9/28/12
to cython...@googlegroups.com
I am replying to myself to let you know that I have tried to use

from defs cimport gint

instead of

from kwant.graph.defs cimport gint

(where I would actually like to do: from .graph.defs cimport gint)

The latter method worked for our defs.pxd which is very simple and
contains a single ctypedef. It does not work for more complex pxd files
which cimport other files.

So, unfortunately, I am stuck with this issue and do not know how to
proceed. If anyone knows of a solution I would be very glad to hear it.

Robert Bradshaw

unread,
Oct 8, 2012, 3:49:43 PM10/8/12
to cython...@googlegroups.com
This is not yet supported, see the discussion at
http://mail.python.org/pipermail/cython-devel/2012-October/003172.html

- Robert
Reply all
Reply to author
Forward
0 new messages