SDL / Pygame does not load PNG images cx_Freeze

I am running Python 3.1 on Windows, and I am trying to pass a Pygame script as an executable via cx_Freeze. Now it seems to work, except that the exe build cannot 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 showed that this happens when the SDL image library is not included. However, SDL_image.dll and libpng12-0.dll both placed by cx_Freeze in my build directory, so it seems to me that everything should be fine. Why not upload a PNG image?

EDIT: I solved this problem by putting my script in Python 2.6 and using py2exe because it had some kind of functionality that I need.

+4
source share
2 answers

Test by pasting some python code to display one message indicating that the libraries are loaded, and another message to indicate that loading the libraries has led to 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" 
+1
source

I have encountered the same problem many times, but I have learned how to deal with it.

Problem There seems to be a conflict between the two possible dependencies. The jpeg.dll file jpeg.dll included in the JRE (on Windows, something like C:\Program Files\Java\jre6\bin\ ), but it is incorrect. It should be included in the Pygame directory located inside your Python installation, in C:\Python31\lib\site-packages\pygame\ . I don't know why cx_Freeze prefers one of the JREs though ...

How to fix it? This is pretty easy. Just copy the correct file (the one from Pygame) to the directory in which you are running the cx_Freeze script. When you run it, the script will first search in the current directory and find the correct jpeg.dll . Your executable file should be able to import PNG images.

+2
source

Source: https://habr.com/ru/post/1310523/


All Articles