After some big frustration I did it! I converted my django app to an "exe" one to run as a single standalone app on windows (using cherrypy as a WSGI server)
But When I try to to set py2exe's option "bundle_files" to "1" (i.e. bundle the python interpreter Python25.dll inside the generated exe) the generated exe crashes with a message talking about kernel32.dll
But when I use "bundle_file" = "2", the generated exe is runing like a charm, but must -of course- have Python25.dll as a separate file beside it.
Anyone experienced a similar behavior, can you please tell me what I'm missing?
Thank you! :)
this post talks all about using py2exe to get a single exe file.
py2exe - generate single executable file
If you post some code i'll take a look, and your error message will help to.
Maybe you can try pyinstaller instead.
I did have this problem before and didn't find a solution ever, but pyinstaller meets my need too and works perfectly.
I also faced similar problem. But mine is with PyGTK. Simple program has no problem with it. Although there is no straight solution, there is an explanation provided here.
It says:
This is based on the Inno sample code in the py2exe distribution. It has worked successfully for a rather complicated PyGTK/Twisted app requiring extra data at runtime (GTK runtime data, GtkBuilder files, images, text data) that just wouldn't work with bundle_files.
Here's The solution:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 3}},
windows = [{'script': "Your_App_Name.py"}],
zipfile = None,
)
Related
I am building a GUI tkinter python3 application and attempting to compile it with py2app. For some reason when I try to launch the .app bundle in the dist folder it gives me this error:
A main script could not be located in the Resources folder
I was wondering why it is doing this, as it is rather frustrating, and I can not find anything about it anywhere. I copied my .py file into the resources folder (Networking.py). Previous to this error I also found an error in the Info.plist. In the key where it states the runtime executable, I found it was trying to get python2.7, which I have updated and am no longer using. I changed it to my current version, which the path for looks like this:
/Library/Frameworks/Python.framework/Versions/3.6/Python
It may be worth noting that it had a strange path previously, which did not look like a proper path to me. It was #executable_path/../Frameworks/Python.framework/Versions/2.7/PythonI removed this completely... Was this wrong? I have no idea about anything about XML, which is what it seemed to be...
Also when compiling this happened:
error: [Errno 1] Operation not permitted: '/Users/Ember/dist/Networking.app/Contents/MacOS/Networking'
Any help would be highly appreciated! Thanks!
EDIT
I actually figured out: a bit of a stupid mistake, but since I'm using python 3.x I have to type in python3 before doing it.
In your "setup.py" file that you used to create the application, did you remember to list all the modules used in your code. For example, if you used the OS and Glob modules, then you would add this to your setup.py next to "OPTIONS":
OPTIONS = {'argv_emulation': True, 'includes':['glob', 'os']}
Basically, anything that you import into your module, you should include in the setup.py. Let me know if that works.
I actually figured out: a bit of a stupid mistake, but since I'm using python 3.x I have to type in python3 before doing it.
I had the same problem.
python setup.py py2app
I tried
python3 setup.py py2app
and it worked just fine. Hope this helps.
I have created a desktop gui application which i want to package. I was directed to use pyinstaller to package it so i did. I have a mainwindow.py file where i import a resource file (converted to python code) as well as other imports going on in there. However when i run the output file,it gives me an error. I suspected it was due to my resource file, from the error so i tried pyinstaller on one of the modules and it worked perfectly. however i keep getting an error with the MainWindow.py file. I have the image of the error here for your consideration. How do i go around this error?
I have managed to solve the problem. After reading this answer, I tried pyrcc4 with the '-py3' flag and it worked. I think without the py3 flag,the resource file is converted into a python 2.x code. And I was trying to interpret py2 code with py3 interpreter. That's my understanding of the problem tho. But in case you have a similar problem,try using the -'py3' flag for python3 interpreter.Good Luck
I am using GUI2Exe to compile my python/pygame, game to a .exe
I have a problem with the font module.
using python 2.7 and the py2exe option in GUI2Exe
I have updated python, pygame and py2exe with the 2.7 versions.
My program runs fine but after I compile it with py2exe I get this.
Here is the error I get:
Fatal Python error: (pygame parachute) Segmentation Fault
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
My game starts off as a console and that part runs. But as soon as the display starts I get the crash.
Thanks
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.
Don't use gui2exe use this file from this link: http://pygame.org/wiki/Pygame2exe
Follow the instructions and modify the file as needed. Place the file in the same directory as the "game" main and run the file from console.
I'm a python programmer and I'm trying to build an executable binary to distribute my software to my clients, even if it's not fully executable I want to be able to distribute my software in a way so that it is convenient for the end user.
I have already tried PyInstaller as well as Py2Exe and I'm facing the same problem with a particular software.
I used the splinter module for my program (which of course is a new high level framework to interact with other frameworks like Selenium) and every time I try to compile it there seems to be a file called "webdriver.xpi" that is always left out from the final package and therefore when the program attempts to execute the web-driver it fails with an IO Error saying that the file "webdriver.xpi" was not found....but other than that the GUI and everything works perfectly fine.
So is there a way to include it even manually? I tried including it manually by browsing to the specific folder # library.zip file but it didn't work.
I'm not really expert in this matter and I rely on GUI2Exe for building everything...and I would really appreciate some advice if possible on how to fix this.
Thanks.
I was at this all day and found a workaround, it's sneaky but it works. In the error message I was receiving I noticed that there was a space between in library .zip. I could not trace it down in the source code for py2exe or selenium. I too had tried putting the xpi file in the library zip and it did not work. The workaround is:
In your setup file use these options:
setup(
console=['yourFile.py'],
options={
"py2exe":{
"skip_archive": True,
"unbuffered": True,
"optimize": 2
}
}
)
Run the py2exe install
Copy the xpi file into the dist directory
That should do it.
You need an instruction in your setup.py to include any resource files in your distribution. There is a couple of ways of doing this (see distutils, setuptools, distribute - depending on what you are using to build your distribution), but the py2exe wiki has an example.
You may need to use this py2exe tip to find your resources if you're installing them into the same directory as your exe.
See this answer for some additional info on including resource files in your distribution.
Here is a solution of your question:
I have modify a code little and it should be work since I had a same issue and I solved it:
from distutils.core import setup
import py2exe
wd_base = 'C:\\Python27\\Lib\site-packages\\selenium-2.44.0-py2.7.egg \\selenium\\webdriver'
RequiredDataFailes = [
('selenium/webdriver/firefox', ['%s\\firefox\\webdriver.xpi'%(wd_base), '%s\\firefox\\webdriver_prefs.json'%(wd_base)])
]
setup(
windows=[{"script":"gui_final.py"}],options={"py2exe":{"skip_archive": True,"includes":["sip"]}},
data_files=RequiredDataFailes,
)
I know this is old, but I wanted to give an updated answer to avoid suggesting that programmers do something manually.
There is a py2exe option to specify a list of data files as tuples. (pathtocopyto, [list of files and where to get them])
Example:
from disutils.core import setup
import py2exe
wd_base = 'C:\\Python27\\Lib\\site-packages\\selenium\\webdriver'
RequiredDataFailes = [
('selenium/webdriver/firefox', ['%s\\firefox\\webdriver.xpi'%(wd_base), '%s\\firefox\\webdriver_prefs.json'%(wd_base)])
]
setup(
console=['MyScript.py'],
data_files=RequiredDataFiles,
options={
**mypy2exeopts
}
)
The only downside I am aware of currently is that you still need skip_archive = True. There are workarounds to get the data files in the library.zip, but I haven't had much luck with the webdriver's info.
I'm trying to compile a python project into an executable. To test this, I've got Py2Exe installed, and am trying to do their Hello.py test. Here is hello.py:
print "Hello World!"
Here is my setup.py:
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
I do the following on the command line:
python setup.py py2exe
And I get it mostly working until it start 'finding dlls needed', at which point we get:
Traceback:
<some trace>
ImportError: DLL load failed: %1 is not a valid Win32 application.
Python version is 2.6.6, and I'm on a 32-bit machine running Windows 7. Any ideas or help most appreciated.
In my experience py2exe is rather difficult to use, a bit hit-and-miss in terms of whether it will work or not, and an absolute nightmare to get working at all with any matplotlib import.
I realise this question is quite old now, but I am not sure why people continue to use py2exe when there are much smoother functioning alternatives available. I have have good results with pyinstaller (which was recommended to me after asking a question here on SO where I was also battling with py2exe). Now every time I have tried it it "just worked", so if you're still interested in packing up python code into executables then try give this app a shot instead.
http://www.pyinstaller.org/
Note: py2exe hasn't been updated for some years, while python and 3rd party modules have, which must be partly why it often doesn't work particularly well these days.
Sounds like step 5 in this tutorial describes what you are experiencing:
http://www.py2exe.org/index.cgi/Tutorial#Step5
I had this same problem, this is what I was able to do Q-A. Basically, I downloaded the updated sqlite dll file from sqlite.org. I replaced the py2exe generated DLL file with this new file. The program worked after that. Do make sure you download the 32-bit DLL, however.