Recently when packaging up a Windows installer for PyKaraoke I came across a problem with Py2exe’s handling of Pygame DLLs.
Py2exe is a utility to convert Python scripts into Windows executables. It should automatically seek out any DLLs required for the application to run independently, and bundle these with the application installer. For a Pygame application a variety of SDL DLLs are used and must be bundled with your applications. The problem is that Py2exe does not successfully pick up all of the required SDL DLLs, missing out libogg-0.dll and sdl_ttf.dll from the final installer package. If your application then attempts to use, for example, the Pygame mixer module, users will be presented with a popup DLL load error message:
"mixer module not available"
The following message will also be sent to stdout:
RuntimeWarning: use mixer: DLL load failed: The specified module could not be found. (ImportError: DLL load failed: The specified module could not be found.)
It turns out that this is due to Py2exe erroneously treating these two DLLs as system DLLs and deliberately excluding them from the package, assuming that they will always be available on a basic Windows install. It is possible to modify your Py2exe script to copy any additional DLL files like these, but a neater method is to override Py2exe’s system DLL check routine. You can then force it to explicitly avoid incorrectly treating particular DLLs as system DLLs. This method is described on the Py2exe website, which should give you all you need to start successfully packaging Pygame applications.