A problem with Cython locating ".pxd" files.

Keywords: cython pxd package hierarchy __init__.py

If you are working on a project involving several different cython/pyrex files scattered through a package hierarchy, you may stumble on this issue.

Let's say you have a module top.sub0.sub1.thing, implemented in the following files:

  top/sub0/sub1/thing.pyx
  top/sub0/sub1/thing.pxd

When building thing.pyx, Cython will fail to see the pxd file unless there is an __init__.py in the sub0 and sub1 directories. This was very non-obvious to me, and since I tend to build packages with cython code first and only later add supporting python code, it never occured to me to drop an __init__.py there.

Finally the following mail message clued me in:

http://mail.python.org/pipermail/cython-devel/2012-February/001863.html
Last modified: Thu May 24 16:18:40 PDT 2012