Search code examples
pythonpython-3.xcx-freeze

Python cx-freeze ImportError: dynamic module does not define init function


I have a program that consists of a main script as .py and some custom modules as .pyd. All the files sit in the same directory. The main script imports the modules using import module syntax, and from my IDE it all works fine. But when I cx-freeze the program I get the error dynamic module does not define init function.

enter image description here

What's doubly strange is that the quavers module is the second import, so the first one works but then this one breaks. And there isn't much difference between the two in terms of content (just a couple of functions in each). I've also created freezed programs before with custom pyd modules and never came across this before.

What is the init function and why does cx-freeze need it? What does it do? Do I need to create an init function in each module that I import?


Solution

  • I figured out the problem. I have two versions of the same module, quavers1 and quavers2. I first compiled them to pyd using nuitka and then renamed the created pyd file from quavers1 to quavers when cx-freezing them. The renaming post nuitka compilation was what was causing the problem. If I rename, compile in nuitka, then freeze, it works fine.