Question

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.

Was it helpful?

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"

OTHER TIPS

I encountered the same issue many times, but I found out how to deal with it.

The problem It seems that there is a conflict between two possible dependencies. The file jpeg.dll is included from the JRE (on Windows, something like C:\Program Files\Java\jre6\bin\), but it is the wrong one. It should be included from the Pygame directory, located within your Python installation, at C:\Python31\lib\site-packages\pygame\. Don't know why cx_Freeze prefers the one from the JRE, though…

How to fix it? It is quite easy. Just copy the correct file (the one from Pygame) to the directory in which you execute the cx_Freeze script. When you will start it, the script will look in the current directory first, and will find the correct jpeg.dll. Your executable should be able to import PNG images now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top