[Pyrex] Circular cimports

Mike Wyatt mwyatt at wi.rr.com
Sat Jun 10 19:10:18 UTC 2006


In C/C++, I believe this problem would be solved like this:

***matrix.h***
#ifndef MATRIX_H
#define MATRIX_H

/* declarations here */
#endif

***matrix.c***
#include "matrix.h"

/* implementation here */

Is there an equivalent to #ifndef in Pyrex?  Or is there any other 
solution to my problem?

> I'm building a little math library in Pyrex, and I'm having trouble 
> with some circular cimports.  I'll post short excerpts from my various 
> files, then show the error that I'm getting when I try to use one of 
> the modules.
>
> ***matrix.pxd**
> *cdef class Matrix:
>     cdef float m[4][4]
>
> ***matrix.pyx**
> *cimport vector
>
> cdef class Matrix:
>     ### a bunch of methods, including ones that create or manipulate 
> Vector objects ###
>
> ***vector.pxd**
> *cdef class Vector:
>     cdef float x, y, z, w
>
> ***vector.pyx***
> cimport matrix
>
> cdef class Vector:
>     ### a bunch of methods, including one that has a Matrix argument ###
>
> After building the Pyrex modules into .pyd files, I run a test 
> module.  The first line imports the matrix module and throws this error:
>
> Traceback (most recent call last):
>   File "C:\Development\SFStratPrototype\math3d\matrixTest.py", line 1, 
> in ?
>     import matrix
>   File "vector.pxd", line 1, in matrix
>     cdef class Vector:
>   File "matrix.pxd", line 1, in vector
>     cdef class Matrix:
> AttributeError: 'module' object has no attribute 'Matrix'
> Press any key to continue . . .
>
> It doesn't seem to like how the modules cimport each other.  I can't 
> see any way to eliminate this circular reference, so what can I do to 
> fix this error?
>
> - Mike Wyatt
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Pyrex mailing list
>Pyrex at lists.copyleft.no
>http://lists.copyleft.no/mailman/listinfo/pyrex
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.copyleft.no/pipermail/pyrex/attachments/20060610/7a151aeb/attachment.html 


More information about the Pyrex mailing list