Search code examples
pythonpygamepyinstaller

PyInstaller .exe file not working


EDIT: I found out that the error is that the resources couldn't be opened. Copying the directory into the folder where the .exe is didn't fix it. I tried removing the resources from the .spec file and the size of the .exe file is now 9 MB as opposed to 52 MB so I'm pretty sure the resources are included, but somehow they can't seem to be opened by the .exe. In case anything is wrong with it, This is my .spec file - I only modified the Tree thing to include the resources, the .exe filename and icon.

In other words, the question now is: Why can't the exe find my game resources, and what do I have to do to fix that? Also, I realised my resources folder has two subfolders - does that mean I have to go about writing the Tree differently?

I've made a game in Python (using Pygame, too) and want to make a single executable file so I can distribute it. PyInstaller seemed perfect for that, and eventually, after a while of searching, I found out how to get it working in this guide. After I tweaked my code to get step 2 working I created the .spec file, added the directory with the resources to it (as in step 5, and including the font file), copied it to the same folder the .spec file was in and finally I ran

build.py game.spec

and I found the .exe file exactly where it was supposed to be. However, when I open it, it just closes again after a few seconds, and I think it's just before the main menu shows up. I'm not really sure it's a font screw-up again though because I made sure to include it in the resources as well...

Unfortunately, searching for a solution on the web didn't help me at all, especially because half the links to the project are broken now.

If anyone knows what's gone wrong here (or needs more details) please let me know.

Details:

Python version: 2.7.7 32 bit

Pygame version: 1.9.3 32 bit

PyInstaller version: 1.5 32 bit

System: Windows 8.1 64 bit (the 32 bit programs have all worked fine so far though)


Solution

  • I didn't find out what the problem was but I did manage to get it working. I started by installing the newer version of PyInstaller (2.1) with pip and completing the same steps again, but this time in the Scripts directory and running pyi-makespec and pyi-build instead of makespec.py and build.py because that's how the new version works, I guess. At first it would still complain about the resources being missing unless I ran it from cmd, but I think that was actually because I forgot step 5 (Tree in the makespec file). For some reason now the .exe can't permanently save the highscores, but apart from that it's working perfectly.