Py2Exe generate log file - python

My problem is that py2exe is generating a log file when I run. It doesn't generate because I have an error when running the program. At the log file there is the standard console print out!
How can I do it that no log file would generate?
here my py2exe setup code:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [{'script': "run.py"}],
zipfile = None
)

In GUI applications, Py2exe redirects sys.stderr to a log file and sys.stdout to an object that ignores all writes. To avoid the log file, do this in your program at the top of the main module:
import sys
sys.stderr = sys.stdout
Or, let py2exe create a console application by using the console keyword instead of windows in setup.py.

Probably you can remove the content of the file! It can work, but you must see if your programm needs some function defined there and then it can get errors!

At the chat you said that you want to use Python 3 but Py2Exe isn't there... Why don't you use cx_Freeze? It generates a bin and an .exe file. You can make an Installation with InnoSetup and you Game is perfect!

Related

.exe made using py2exe not doing anything

I'm using Python 2.7.9 on Windows 7 x86
the file i'm trying to make into an executable has the following source code:
import Tkinter
root=Tkinter.Tk()
root.mainloop()
Yeah, not much, just an empty window.
The setup file is:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
s=raw_input("Name:")
s=s+".py"
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [{'script': s}],
zipfile = None,
)
When i run the exe, nothing happens, even when using cmd. I get no errors either, it just... does nothing.
I've always found cx_freeze easier to use on Windows
http://cx-freeze.sourceforge.net/

Py2exe compiles properly but the built application doesn't work

I am using Python 2.7 to build my application. Within it, I used few packages which are numpy, scipy, csv, sys, xlwt, time, wxpython and operator.
All the above packages are in 64-bit, and I am using python 2.7(64-bit version) in Aptana Studio 3(64-bit version) in Windows 7 Professional (64-bit version).
At last, I'd like to compile my project to an application using following code, the file name is py2exeTest.py:
from distutils.core import setup
import numpy # numpy is imported to deal with missing .dll file
import py2exe
setup(console=["Graphical_Interface.py"])
Then in cmd, I switched to the directory of the project and used following line to compile it:
python py2exeTest.py py2exe
Everything goes well, it generates an application under dist directory, and the application name is Graphical_Interface.exe.
I double clicked it, but there is a cmd window appears, and a python output windows flashes, then both of them disappeared. I tried to run the application as an administrator, the same outcome I've had.
May I know how to work this out?
Thanks!
EDIT:
I've managed to catch the error information that flashes on the screen. The error info I had is:
Traceback (most recent call last):
File "Graphical_Interface.py", line 397, in <module>
File "Graphical_Interface.py", line 136, in __init__
File "wx\_core.pyc", line 3369, in ConvertToBitmap
wx._core.PyAssertionError: C++ assertion "image.Ok()" failed at ..\..\src\msw\bitmap.cpp(802) in wxBitmap::CreateFromImage(): invalid image
I used one PNG image in the project, the code is like follows:
self.workflow = wx.Image("Work Flow.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(self.panel_settings, -1, self.workflow, (330,270), (self.workflow.GetWidth(), self.workflow.GetHeight()))
I tried to comment the above chunk out from the project, and the application works properly. However, I need the image to show up in the application.
May I know how to deal with it?
Thanks.
Hiding console window of Python GUI app with py2exe
When compiling graphical applications you can not create them as a console application because reasons (honestly can't explain the specifics out of my head), but try this:
from distutils.core import setup
import numpy
import py2exe
import wxpython
setup(window=['Graphical_Interface.py'],
options={"py2exe" { 'boundle_files' : 1}})
Also consider changing to:
http://cx-freeze.sourceforge.net/
It works with Python3 and supports multiple platforms.
A cx_freeze script would look something like:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
includefiles = ['/folder/image.png']
setup( name = "GUIprog",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options, 'include_files' : includefiles},
executables = [Executable("Graphical_Interface.py", base=base)])
No worries, I've got the solution.
It turns out that the image is in the project folder rather than in the dist folder. So I have two solutions:
Copy the image into dist folder
Include the full path of the image in the code.
Thanks for your help.

Py2Exe local server does not execute CGI

I have a certain Python program that relies on a CGI script, which works when I launch a Python BaseHTTPServer with a CGIHTTPServer. But I would like all this to be run without installing Python, so I used Py2Exe.
I manage to create a .exe from my script, which indeed creates a working local web server when executed. CGI scripts, however, are just shown as code and not executed.
Here's the whole server script, which also launches the default browser:
#!/usr/bin/env python
import webbrowser
import BaseHTTPServer
import CGIHTTPServer
server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8008)
handler.cgi_directories = ["/cgi"]
httpd = server(server_address, handler)
webbrowser.open_new("http://localhost:8008/cgi/script.py");
httpd.serve_forever()
However, that script.py is just shown and not executed. I can't figure out why, and I have tried a few different versions in handler.cgi_directories, just in case...
problem is py2exe only converts your server script to exe, all cgi scripts are still .py and they require python installation to run. try converting each and every script in 'cgi' directory.
Assuiming you have server.py in root dir and cgi scripts at wwwroot\cgi-bin your setup.py should look like
#!usr/bin/env python
from distutils.core import setup
import py2exe, os
setup(name='server',
console=['server.py'],
options={
"py2exe":{
"unbuffered": True,
"packages": "cgi, glob, re, json, cgitb", # list all packages used by cgi scripts
"optimize": 2,
"bundle_files": 1
}},
zipfile="library.zip")
os.rename("dist\\library.zip","dist\\library.zip.bak") # create backup of the library file
files=[]
for f in os.listdir("wwwroot\\cgi-bin"): # list all cgi files with relative path name
files.append("wwwroot\\cgi-bin\\"+f)
setup(name='cgi',
console= files,
options={
"py2exe":{
"dist_dir": "dist\\wwwroot\\cgi-bin",
"excludes": "cgi, glob, re, json, cgitb", # we are going to discard this lib, may as well reduce work
"bundle_files": 1
}
},
zipfile="..\\..\\library.zip") # make sure zipfile points to same file in both cases
os.remove("dist\\library.zip") # we don't need this generated library
os.rename("dist\\library.zip.bak","dist\\library.zip") # we have already included everything in first pass

Best of both worlds: python packaging for a game

I am currently trying to package a game made with python and pygame and I am running into some issues.
I am using py2exe to package and have looked up some question on here about it but I couldn't find a great solution. I want to end up with a folder, containing an exe, that I can compress and put online. Running the setup.py works fine except it puts all the dependencies into library.zip. This means that the program, when run, does not work.
I found that someone else was running into this issue and they ended using the "skip archive = true" option to solve it. And while, yes, that does work for me too I was hoping there was a method that would still let the program be run without trouble but wouldn't clutter the folder with countless files.
To be very precise the issue I'm running into with the library.zip is:
ImportError: MemoryLoadLibrary failed loading pygame\mixer.pyd
Which, if I understand it properly, means that the program can not reach/find the mixer module of Pygame.
Here is the setup script I am currently using (and that isn't working):
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
data_files = [('resources', ['resources/step.wav',
'resources/wind2.wav',
'resources/The Steppes.ogg',
'resources/warrior3-nosword-notassle.png',
'resources/warrior3-sword.png',
'resources/warrior2-blood1.png',
'resources/warrior2-blood2.png',
'resources/warrior2-blood3.png',
'resources/warrior2-blood4.png',
'resources/warrior3-up.png',
'resources/warrior3-kneel.png',
'resources/warrior3-kneel-nosword.png',
'resources/warrior2-blood2-kneel.png',
'resources/warrior2-blood3-kneel.png',
'resources/warrior2-blood4-kneel.png',
'resources/warrior3-death.png',
'resources/warrior3-offarm.png',
'resources/menu1.png',
'resources/plains3-top-nomount.png',
'resources/mountains.png',
'resources/plains5-bottom.png',
'resources/plains3-bottom.png',
'resources/cloud1.png',
'resources/warrior2-sword.png',
'resources/warrior2-hand.png',
'resources/blue-tassle1.png',
'resources/blue-tassle2.png',
'resources/blue-tassle3.png',
'resources/blue-tassle4.png'])]
setup(options = {'py2exe': {"bundle_files": 1}},
data_files = data_files,
console = [{'script': "steppes2.0.py"}],
zipfile = None
)
This code in your setup.py should do the trick of producing a single executable (you will still have to distribute msvc dlls separately)
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
console = [{'script': "myscript.py"}],
zipfile = None,
)

running a python script as administrator

i'm writing an installer using py2exe which needs to run in admin to have permission to perform various file operations. i've modified some sample code from the user_access_controls directory that comes with py2exe to create the setup file. creating/running the generated exe works fine when i run it on my own computer. however, when i try to run the exe on a computer that doesn't have python installed, i get an error saying that the import modules (shutil and os in this case) do not exist. it was my impression that py2exe automatically wraps all the file dependencies into the exe but i guess that this is not the case. py2exe does generate a zip file called library that contains all the python modules but apparently they are not used by the generated exe. basically my question is how do i get the imports to be included in the exe generated by py2exe. perhaps modification need to be made to my setup.py file - the code for this is as follows:
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
)
Try to set options={'py2exe': {'bundle_files': 1}}, and zipfile = None in setup section. Python will make single .exe file without dependencies. Example:
from distutils.core import setup
import py2exe
setup(
console=['watt.py'],
options={'py2exe': {'bundle_files': 1}},
zipfile = None
)
I rewrite your setup script for you. This will work
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
#the options is what you fail to include it will instruct py2exe to include these modules explicitly
options={"py2exe":
{"includes": ["sip","os","shutil"]}
}
)

Categories