Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have just compiled part of my C library as an extension using Cython, as a "proof of concept". I managed to hack the code (const correctnes problems etc aside), to finally get an extension built.

However, when I attempted to import the newly created extension, I got the following error:

ImportError: dynamic module does not define init function  

What am I doing wrong and how do I fix this?

I am using Cythn 0.11.2 and Python 2.6.5 on Ubuntu 10.0.4

like image 439
Homunculus Reticulli Avatar asked Nov 06 '11 02:11

Homunculus Reticulli


1 Answers

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.

like image 91
Dologan Avatar answered Oct 02 '22 08:10

Dologan