问题
I am working on a problem with my 2D arcade game programed with Python using the module pygame
for 2 days now and I can't find a solution.
The problem is: I want to create a Windows Executable File that is running my program correctly. I already managed to create a .exe
file, but I get an error as soon as I start the exe:
Runtime Error!
Path\MyGame.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I tried to create the .exe
file with every module that makes it easy to build one, for example cx_freeze
, py2exe
, pyinstaller
. At the end it doesnt matter which one I have used, I got the same error. I already tried to start the .exe
file with another PC, it failed. Updated my Microsoft Visual C++ Redistributable, nothing helped.
So the fault must be somewhere in my code. The program is running correctly, but there must be something that prevents me from making a .exe
file that works fine.
The code has around 1000 lines, I know it's too much to ask for someone checking the whole code but I hope someone had a similiar problem to this or have some tips why this error is appearing and can help me.
You can find the code here.
回答1:
The problem is not your code, the problem is how you generate your .exe. Doing that with pygame is a real bitch, but with some hacking and google'ing you can do it.
This should get you started: http://pygame.org/wiki/Pygame2exe
回答2:
Had similar problems and that one too. Found a way to solve them:
After few weeks (had this problem even before) I'm happy to say that I solved this problem! :)
1st part of my problem (http://i.stack.imgur.com/WpkjR.png): I solved it by editing setup.py script with adding "excludes" part in it. That resulted in successful making of executable file!
Modified setup.py script:
from distutils.core import setup
import py2exe
setup(windows=['source_static.py'], options={
"py2exe": {
"excludes": ["OpenGL.GL", "Numeric", "copyreg", "itertools.imap", "numpy", "pkg_resources", "queue", "winreg", "pygame.SRCALPHA", "pygame.sdlmain_osx"],
}
}
)
So, if you have similar issues, just put those "missing" modules into this "excludes" line.
2nd part:
After I succeeded in making of executable file, I had next problem: "The application has requested the Runtime to terminate it in unusual way. Please contact...". After days and days of searching and thinking how to solve this another problem, I found a way to do it. I couldn't believe that the problem was so absurd. The problem was in my code, with font definition:
font1 = pygame.font.SysFont(None, 13)
After changing "None" to some system font name (for an example "Arial" (must be a string)), and compiling, I couldn't believe that my .exe file worked!
font1 = pygame.font.SysFont("Arial", 13)
Of course, you can use your own font, but you must specify its path and define it in your program.
So for all of you who are experiencing this issues, try this steps and I hope that you will succeed. I really hope that this will help you, because I've lost days and weeks trying to solve these problems. I even tried making my .exe file with all versions of python and pygame, with many other .exe builders and setup scripts, but without luck. Besides these problems, I had many other problems before but I found answers to them on stackoverflow.com.
I'm happy that I found a way to solve this problems and to help you if you are faced with the same ones.
Small tips (things I've also done):
1st: update your Microsoft Visual C++ library to the latest one.
2nd: if you have images or fonts similar that your executable program needs, include them to dist folder (where your .exe file has been created).
3rd: when you are making your .exe file, include all needed files to the folder where your setup.py script is (all files and directories that your main script uses).
Used Python 2.7 x64, pygame and py2exe.
回答3:
Had the same problem, solved it by putting pygame's default font file in the distribution folder. It was used in project, and I'd assumed it would be included in the build automatically.
来源:https://stackoverflow.com/questions/9018065/pygame-distribution-runtime-error