Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython cimport and __init__.pyx buggy?

Tags:

import

cython

It seems like compiling an __init__.pyx that contains a cimport statement is buggy.

This is my folder-structure:

DrawAPI\
    __init__.pyx
    utils.pxd

The __init__.pyx:

cimport utils

Compiling the __init__.pyx with cython gives me that utils.pxd could not be found. But renaming __init__.pyx to any other name, like foo.pyx for instance

DrawAPI\
    foo.pyx
    utils.pxd

and then compiling foo.pyx works just fine.

Am I doing something wrong ?

like image 928
Niklas R Avatar asked Aug 13 '11 10:08

Niklas R


1 Answers

If a directory contains an __init__.py or __init__.pyx file it is assumed to be a package directory. So in your example the utils module is assumed to belong to the package DrawAPI and its FQMN is DrawAPI.utils

However, if DrawAPI is the current directory you're running the compiler from, and you haven't added DrawAPI to the include path the utils.pxd won't be found (as you have discovered...)

If you intend utils to be a top-level module then you will have to move it somewhere else where there is no __init__.pyx file.

If you intend it to reside in a package, then cd to the directory containing DrawAPI and compile from there.

like image 123
Fraser Avatar answered Sep 29 '22 17:09

Fraser