Trying to cimport pxd definitions from other packages.
Simple example, a.pxd file:
cdef inline void a():
print "a"
b.pyx file:
cimport a
def b():
a.a()
Until here, everything is ok, and $ cython b.pyx
works.
If i move a.pxd to a folder, e.g libs/
, then I change b.pyx to:
from libs cimport a
def b():
a.a()
and then I have the error:
$ cython b.pyx
Error compiling Cython file:
------------------------------------------------------------
...
from libs cimport a
^
------------------------------------------------------------
b.pyx:1:0: 'a.pxd' not found
Error compiling Cython file:
------------------------------------------------------------
...
from libs cimport a
^
------------------------------------------------------------
b.pyx:1:0: 'libs/a.pxd' not found
But libs/a.pxd is there. What would be the right way to import pxd definitions from other packages?
A directory is not a package unless it contains a
__init__.py
file, even if the file is empty. So add an empty__init__.py
file to thelibs
directory.With this directory structure, your
a.pxd
andb.pyx
,setup.py
andscript.py
(below),Running
script.py
works:setup.py:
script.py: