Cython compiled C extension: ImportError: dynamic module does not define init function Cython compiled C extension: ImportError: dynamic module does not define init function python python

Cython compiled C extension: ImportError: dynamic module does not define init function


I've found that a frequent cause of this problem is, when using a distutils setup file to compile the code, that the .pyx base name does not match the extension name, e.g:

ext = Extension(name='different', sources=['cython_ext.pyx']) # Won't work

To avoid the problem the extension name should be exactly the same, in this case, cython_ext.


It appears that it's a bug/feature in Cython. I had the same thing, but simply added:

STUFF = "Hi"

to the top of my .pyx file and the issue went away. It appears if there is no global initialization (a cinit or setting a global variable), that the required initialization code isn't generated.


This is a very late answer - but I just had the same error, and mine went away when I used __cinit__ instead of __init__. I'm still learing about extension types so currently I do not know why this happens. :) (You can take a look at http://docs.cython.org/src/reference/extension_types.html#initialization-cinit-and-init) Hope this is useful to someone.