On Tue, May 4, 2010 at 8:36 AM, Gabriele Lanaro
<[email protected]> wrote:
> Hi!
> In the project I'm working on there is a splitting between extension source
> files and pure python source files. I've some problems in compiling
> correctly the extensions:
> Src/cython/
>          one.pyx
>          one.pxd
>          two.pyx
>          two.pxd
>          ...
> Package/
>          __init__.py
>          stuff.py
>          ...
>
> one,two etc are dependent each other ("two" has a cimport statement in it)
> When compiling the situation should be:
>
> Package/
>       __init__.py
>       stuff.py
>       one.so
>       two.so
>       ...
>
> When importing two.so there's an import error like this (name are different
> but the concept is the same):
>
> File "primitive_gto.pxd", line 18, in contracted_gto
> (Src/PyQuante/contracted_gto.c:1843)
> ImportError: No module named primitive_gto
>
> If I move the .pyx and .pxd files in Package the compilation goes ok. How
> can I obtain a correct compilation using the first package structure?
>
> (I really need that, it's not my choice)

Looks like Cython (and Cython's distutils) needs to know about the
package structure at compile time to get everything setup right.

One solution would be the following.  Arrange your directory structure
like this:

.
|-- Makefile
|-- Package
|   |-- __init__.py
|   `-- stuff.py
`-- src
    |-- Package
    |   |-- __init__.py
    |   |-- one.pxd
    |   |-- one.pyx
    |   |-- two.pxd
    |   `-- two.pyx
    `-- setup.py

Essentially you create a parallel package structure with the cython
sources, and tell distutils to put the compiled extension modules in
the right place.

Here's the contents of the makefile:

$ cat Makefile
all:
        (cd src && python setup.py build_ext -b ..)

clean:
        -rm -r src/build
        -rm Package/*.so
        -rm src/Package/*.c

I've attached this solution to the email -- hopefully it gives you the idea.

Kurt

Attachment: test_cython_compile.tgz
Description: GNU Zip compressed data

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to