Py2exe and Pygame DLLs

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.

Bookmark and Share This Article
[del.icio.us] [Digg] [Google] [Reddit] [Slashdot] [StumbleUpon] [Technorati] [Twitter] [Yahoo!] [Email]
This entry was posted in HowTo and tagged , , , . Bookmark the permalink.

One Response to Py2exe and Pygame DLLs

  1. Jasper says:

    Thanks for writing about this. I just updated all my libraries after sitting at python 2.4 forever, and have been stumbling over py2exe’s conflict with mixer.

    I’ve also read that going back to an older version of py2exe avoids this issue:

    http://www.moviepartners.com/blog/2009/03/20/making-py2exe-play-nice-with-pygame/

Leave a Reply

Your email address will not be published. Required fields are marked *