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.
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
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.
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.
Related
This question already has answers here:
How can I convert a .py to .exe for Python?
(8 answers)
Closed 2 years ago.
I have Python 3.6 and I did a project in .py that I would like to put in an .exe document ;
How can I do that ? I tried Py2exe but it did not worked due to my python version.
Thanks for your answers.
Traftmine
I faced this problem some times ago, after a lot of googling I found the best solution for me.
Alternatives
Py2Exe: Which is old, the last release on PyPi is on 21 October 2014.
pyInstaller: Is a nice tool, but with some problem that we will see later.
auto-py-to-exe: Use pyInstaller to build the .exe, so suffer the same problem, but has a nice GUI and is intuitive to use.
cx_Freeze: I think the best solution, because it was the only one that works in my case, it is also recommended from python
Investigation
During this time I looked on google and StackOverflow for the best solution, each time that I found something it was out-dated or not well explained/documented, so I studied the official docs.
py2exe
As first try I installed py2exe it seems the best option, also recommended from python, so, give it a try.
All goes fine during the installation process, so I decide to follow the tutorial and get my .exe.
During the step 3 of the tutorial, running setup I received an error, looking on google I found this.
I gave up with py2exe.
auto-py-to-exe && pyInstaller
I have installed auto-py-to-exe and all went good, the program open without problems so I create my .exe file, that works!
The only problem was that, the program works only on my laptop, on all the other machine where I try to execute the antivirus delete it.
Looking on google I found the github repository where I found one issue like the mine, reading it I understand that the problem is pyInstaller.
Looking on the pyInstaller repository I found one issue where one contributors tells to contact the antivirus vendor, so I gave up again.
cx_Freeze
Looking the docs it seems to be overcomplicated realize a simple .exe, so I have studied the documentation and found what I need.
Open you project folder and create inside it a setup.py file with inside:
from sys import executable
from cx_Freeze import setup, Executable
setup(name='programName', version='0.1', description='my fancy description')
Setting up this file require a little bit of study, there are multiple options to set. You can set the option to create a simple .exe or also the create a windows/mac/linux installer.
Once you have your file ready, with the options that you need, just open a shell/terminal/cmd in the directory where the setup.py file is located and execute: python setup.py build
Now in your project folder you will see a folder where inside you can find your .exe file.
You should check out PyInstaller.
I've been searching for a while now and I can't seem to find any help on this one...
My scenario: I got a python/kivy project and I already got my python-files compiled using setup and cythozine().
My problem: I somehow have to compile, or at least obfuscate the .kv files. Please don't ask me why, I've seen many discussing it and mostly it goes nowhere. It was requested that way and I do not want to discuss it.
My solution so far: I inject the whole content of the .kv-File into the Builder.load_string() before compiling my scripts, but that whole string will appear in plain text in the compiled files after compiling them. It will take some time for someone to find it, but I think it's still not the best solution.
Hopefully someone can help me out here. ^^
EDIT:
I've already tried the following, so I could at least obfuscate the code: https://github.com/rdevost/pymixup
Unfortunately, the pre-requisites gave me some problems.
I asked for the obfuscation, since it seems quite troublesome to compile it. So I thought it might be a compromise to obfuscate the kv-File, load it into the Builder and compile the py-File. With that, the kv part would still be in plain text inside the compiled file, but it would be obfuscated.
I'm running my application on a raspberry pi.
Ok... That was pretty simple. I just had some trouble figuring out how PyInstaller works.
I used the simplest method of PyInstaller to compile it.
python -m PyInstaller --name Project-Name -p {Some custom Submodules-Path} main.py
Before doing that, I injected the kv-Language code into the py-script as an input-string for the kivy-module Builder.load_string().
Not as elegant as I hoped, but anyway... If someone has any idea how to include the kv-Lang files, I would appreciate it. I know one can add some hooks to it after creating the .spec of PyInstaller. kivy: Create a package for windows But that's it.
The result is significantly larger than before (setup + cythonize). But it works for me, since it's compiled and a bit obfuscated too so you can't read the code that easy. ^^
This might be a simple task, but it took me some time to figure it out.
I have tried many times to use a compiler like cx_freeze and other programs, but for some reason nothing seems to be working. I made a little game which I want to send to a friend, but he needs python installed.
Can't I just put python.exe and pygame into the folder that I will send my friend and won't python be installed then, and all he needs to do is run the program .py and it will work? Sorry if I'm not being clear.. I'm just trying to find a simple way to compile my code to let users not waste time on downloading pygame and python.
py2exe allows you to package python applications for Windows. Right now it supports everything from 2.4 - 3.1 of python. You do however need to be able to redistribute MSVCR90.dll.
There are a range of distribution tools and you can find a list here.
Since you've had difficultly with several tools now updating your question with error codes and speific problems will yeild better responses.
From my knowledge, just putting a bunch of your stuff in one folder and sending doesn't work. It would be easier to make a .exe
That way your stuff will be protected, and users can easily start it. Otherwise idk. Try using pyinstaller again. It should work if you have a python.x
CX_Freeze is known for having many bugs and problems, Pyg.exe is new to me also. Your best bet is just keep trying until you find a solution.
Putting python.exe and your script together in a folder will not work for distribution. You require all Python dependencies - at best your would need to include all of your Python folder, and it still might not work. The best method would be compilation or packaging with programs such as py2exe, cx_freeze, Cython, pyg.exe, etc.
This question already has answers here:
a good python to exe compiler? [closed]
(3 answers)
Closed 9 years ago.
With some useful answers of my previous question (See below), I decided to give py2exe another try.
I tried the tutorial from py2exe.org (http://www.py2exe.org/index.cgi/Tutorial), but got an error at step 3. I did 1 and 2 exactly as told, and put both files (hello.py and setup.py) in my main folder where I installed python in: D:\Programs\Python.
When running the 'code' form step 3 I got the following error, totally on the bottom of the output:
"ImportError: DLL load failed: %1 is not a valid Win32-application.*"
I've got a screenshot of the entire output, but I don't know where to upload it.
Extra information:
I have 64bit Windows 7 (profesional) and Python 2.7.3 (first I had 3.3.0, but downgraded because of some reasons). It is not a big problem for me to change to another version. I downloaded py2exe 0.6.9.
Note: I couldn't choose between py2exe for 32- or 64bit. I guess then a error should show up earlier, but it might be handy to know.
*I literally translated the last part from Dutch, so it can be slightly different then English pc's.
Previous question:
What is the easiest .py to .exe converter?
I've tried a few converters, of which cx_Freeze and py2exe. Using cx_Freeze was too complicated (I couldn't find a good tutorial) and py2exe gave some errors. Before I'm going to try to understand one of these two or try another one, I want some input which converter you think is the best, and I need a good tutorial.
I have barely experience with cmd, and am quite a newbie if it comes to programming/python, so I am looking for the easiest-to-use converter.
If you say I really need some cmd experience, please direct me to a cmd tutorial/course.
you can use GUI2exe that's the easiest way im my opinion !
You wont learn much about the converter's but it gets the job done without any problems.
ps. GUI2exe isnt a converter , its a gui to use the converters!
What kind of erros does py2exe give you? That is what I use and it works like a charm for me.
I've used py2exe previously. I assume you've looked at the tutorial on the py2exe project page?
There is also a good one available on the Python Library page.
I used py2exe for complicated Python/Qt/PyQt applications. The biggest thing you'll need to know about that is that the MSVCP90.dll file is needed. You can get that from Microsoft. You'll then need to copy it and the other files mentioned in it's license to the Python DLLs directory. Detailed instructions are available on the py2exe tutorial (Step 5)
Try py2exe and cx-freeze. These are the two most common ones you'll find out there. Most others are generally a derivative of cx-freeze
So, I've got a program I made in python 2.6, it ran fine as normal python, and ran fine when made into an exe via py2exe v0.6.9. I used signtool to sign it, having changed nothing else, and it stops working.
When I run the signed exe, I receive an "ImportError: No module named os" from line 1 of my script. I did some digging and found this: http://osdir.com/ml/python.py2exe/2008-04/msg00031.html, which seems to be a very close description of my problem. I manually applied the patch linked to from the py2exe website to my build_exe.py file, though I was running py2exe 0.6.9 instead of 0.6.6, so I tried to take that into account. Still no love.
According to the link, this seems to be a py2exe issue. I don't know though. Any help would be much appreciated. And of course, I'll answer any other questions I can that you have about this. Thanks for the help!
If it's a py2exe issue, maybe give the newer PyInstaller a shot to build your executable. It's in active development, unlike py2exe which apparently hasn't been updated since 2008-11-16.