"dynamic module does not define init function"

2,700 views
Skip to first unread message

Julien Delafontaine

unread,
Jan 5, 2016, 9:00:19 AM1/5/16
to cython-users
Hi again
What can i do to get around this one ? (occurs at import time - the compilation and build were fine):

ImportError:
dynamic module does not define init function (PyInit_myextension)

I searched the web without much success.
(In particular, the solutions mentioned here did not work).

I am building as simply as possible, with distutils and cythonize().

Julien Delafontaine

unread,
Jan 5, 2016, 9:16:42 AM1/5/16
to cython-users
A, cythonize() created "myextension.cpython-34m.so" instead of "myextension.so"... Is that why ? Any reason to this ? Any way to get it back to normal ?

Julien Delafontaine

unread,
Jan 5, 2016, 9:36:16 AM1/5/16
to cython-users
The extension is not the cause. The module is not recompiled by cythonize() if a .c is already found - when I distribute my package to another machine, I need to recompile first manually. Python setup.py sdist includes the .c into the archive.

Chris Barker - NOAA Federal

unread,
Jan 5, 2016, 11:15:07 AM1/5/16
to cython...@googlegroups.com

A, cythonize() created "myextension.cpython-34m.so" instead of "myextension.so"... Is that why ? Any reason to this ? Any way to get it back to normal ?

That is normal -- newer pythons create these convoluted names to assure that you don't load an extension built for a different version of Python.

Have you posted an as-simple-as-possible example that fails? Pyx and setup.py.
    ImportError: 
dynamic module does not define init function (PyInit_myextension)
Cython sure should be adding that init function, something is odd.

CHB




I searched the web without much success.
(In particular, the solutions mentioned here did not work).

I am building as simply as possible, with distutils and cythonize().

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oscar Benjamin

unread,
Jan 5, 2016, 11:28:37 AM1/5/16
to cython-users
On 5 January 2016 at 16:15, Chris Barker - NOAA Federal
<chris....@noaa.gov> wrote:
>>
>> ImportError:
>> dynamic module does not define init function (PyInit_myextension)
>
> Cython sure should be adding that init function, something is odd.

This can happen if the file name is wrong. CPython will identify
X.cpython-34m.so as being a module with name X, load the .so and try
to call PyInit_X so if you rename the .so you get this error.

--
Oscar

Julien Delafontaine

unread,
Jan 5, 2016, 11:54:58 AM1/5/16
to cython-users
It happened with this minimal configuration:

    https://groups.google.com/d/msg/cython-users/vox0ECQlo_Q/x7ICiI79DAAJ

Not locally, where I developed, but after the following steps:

On the mac (the code works fine) :
- python setup.py build_ext --inplace    # local development
- python setup.py sdist     # .c extensions are also copied to /dist by default, for some reason
- archive /dist
- scp dist.tar.gz @some-linux-server

On the linux machine:
- extract dist.tar.gz
- python setup.py build_ext --inplace   # uses the already present .c instead of recompiling
- try to import the extension: error.

So on the new machine, one has to remove the .c before rebuilding. I excluded it in MANIFEST.in and now it works.

The problem is more that the error message is very cryptic.

Chris Barker

unread,
Jan 5, 2016, 3:48:23 PM1/5/16
to cython-users
sorry, limited time, but if this is working differently on a Mac than Linux:

OS-X has a weird, sometime case-insensitive file system. Linux is fully case sensitive, so make sure ALL your names are consistent and all lower case.

-CHB


--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris....@noaa.gov
Reply all
Reply to author
Forward
0 new messages