pythonsdlpygamecx-freeze

SDL/Pygame failing to load PNG images with cx_Freeze


I'm running Python 3.1 on Windows and I'm trying to distribute my Pygame script as an executable via cx_Freeze. Right now it seems to be working except that the exe build can't load any of my images:

Cannot load image: C:\path\to\build\exe.win32-3.1\resources\image.png
File is not a Windows BMP file

Googling has revealed that this happens when the SDL imaging library doesn't get included correctly. However, SDL_image.dll and libpng12-0.dll are both put by cx_Freeze into my build directory, so it seems to me like everything should be fine. Why wouldn't it be able to load PNG images?

EDIT: I "solved" this problem by porting my script to Python 2.6 and using py2exe instead since it had some functionality anyway that I needed.


Solution

  • Test by inserting some python code to display one message indicating that the libraries have loaded and another message to indicate that their loading resulted in an error.

    try:
       import SDL_image
       print "Loaded SDL_image"
    except:
       print "Failed to import SDL_image"
    
    try:
       import libpng
       print "Loaded libpng"
    except:
       print "Failed to import libpng"