Reputation: 4749
I'm trying to compile a quick extension for a module that was pre-compiled on install (.pyd
). Below is a simplistic example of what i'm trying to do. Given foo.pyd
:
from foo.bar cimport Bar
cdef class Baz(Bar):
pass
cdef class Baz(Bar):
def __init__(self, *a, **k):
...
from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
extensions = [Extension('baz', ['baz.pyx',], libraries=['foo.pyd',])]
setup(name='baz', ext_modules=cythonize(extensions))
I've tried many variations of the above, to no avail.
Upvotes: 6
Views: 868
Reputation: 363567
cimport
is for C/C++ APIs (functions, structs, classes) and reads from .pxd
files, which are the Cython counterpart to C/C++ headers. If you don't have a .pxd
for the foo
library at compile-time, you cannot cimport
from it. Python extension modules (.pyd
on Windows, .so
on Linux) typically don't have C APIs at all: they only contain externally visible symbols that allow the Python module importer to recognize their contents as a Python module.
Also, if you want to get a Python class (even one implemented as an extension type) from a module, you need to import
it. I don't think a cdef class
is allowed to inherit from such a class, though.
Upvotes: 5