[Pyrex] compiling more .pyx and .pxd files into one .so

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Sep 16 03:29:04 CEST 2007


Stefano Esposito wrote:
> Btw I compiled an unique .so file, but it wouldn't work, complaining about
> the lack of "foo module" when importing in python... 

If you just link all the modules together, e.g. the code
for "foo" and "blarg" into a single file called foo.so,
then when Python code tries to "import blarg" it will
fail because there is no file called "blarg.so". Python
has no way of knowing that it should look inside
"foo.so" instead.

My suggestion is to put a call to initblarg() in the
module body of foo.pyx. Then doing "import foo" will
create the module object for blarg as well and put it
in sys.modules. So when Python code subsequently does
"import blarg" it will already be there.

--
Greg



More information about the Pyrex mailing list