Discuss PY2EXE step-by-step guide in the Python Programming forum on Dev Shed. PY2EXE step-by-step guide Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
Posts: 2,537
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 67
Like it Grim!
That is if you hadn't guessed by the fact that I've stuck this thread to the top of the forum [for the time being] . Anyway, one trivial thing I would add is an alternative way to get the command prompt/DOS prompt under Windows,
Quote:
Start > Run > Type 'command' or 'cmd'
This isn't really that important... just a personal preference really and very handy little thing to know in general . Very cool!
Mark.
__________________
programming language development: www.netytan.com– Hula
Yep - everything you need is already described on the official py2exe website and wiki. But - based on the number of forum posts it is clear that people don't get it
My aim was to illustrate few basics such as:
* Python code is stored as modules and they are text files
* Setup.py is separate from the module you want to compile
* Create a workspace directory
* Use a DOS box to run Python
These seem to be the things that first timers don't quite get and yet the tools they want to use assume these things are already understood.
Posts: 68
Time spent in forums: 14 h 58 m 22 sec
Reputation Power: 8
Using Py2exe with Python Imaging Library (PIL )
Using Py2exe with Python Imaging Library (PIL )
Creating standalone windows executables on widows using is py2exe is pretty straight forward . But you might sometime run into unexpected problems like
You might get the follwing errors while running the exe file created by the py2exe
1 . LookupError: no codec search functions registered: can't find encodingsolution : explicitly include the encodings package:
like this : python setup.py py2exe -p encodings
Un located modules *are* normal. A lot of modules have conditional
imports of other modules that they don't really *need*. This means
py2exe tries to include them in case they are needed. This sometimes
means you have more modules than you really need - and also reports of
modules that can't be found.
2 . Include the PIL switch on the py2exe line
The py2exe line needs to be:
python setup.py py2exe -p encodings –pPIL
It worked for me even without that switch use that in case u run into problems .
3 . File "Image.pyc", line 1571, in open
IOError: cannot identify image file
Solution : In order to make PIL and PY2EXE work together all libraries of PIL need to be imported explicitly such as:
import Image
import BmpImagePlugin # if you are using bitmaps
Import JpgImagePlugin # if you are dealing with jpg images
So forth ..
Note : These explicit imports may not be necessary if you are running the python script directly but are needed if you are running the exe file created by py2exe .
Posts: 12
Time spent in forums: 3 h 14 m 21 sec
Reputation Power: 0
Excellent. I tried it using the example setup.py that came with py2exe for use with INNO and it worked almost perfectly except for a dll that somehow didn't get linked. I have to investigate further for what may have happened, it was msvcr71.dll. Thanks for the tip and clean tut.
Posts: 350
Time spent in forums: 2 Days 11 h 53 m 20 sec
Reputation Power: 26
I have modified Paul Hardwick's code when using Py2Exe with wxPython to avoid the codec LookupError when you run the exe file.
Code:
# run this code to create a windows exe file
# save in the working directory where your code file is
# and run the program from there
from distutils.core import setup
import py2exe
import sys
sys.argv.append("py2exe")
# usually needed for wxPython code to prevent the
# "LookupError: no codec search functions registered" when you run the exe
opt = {"py2exe": {"packages": ["encodings"]}}
# insert your own code filename here ...
setup(options = opt, windows = [{"script": 'myCodeFile.py'}])
Posts: 68
Time spent in forums: 1 Day 15 h 7 m 19 sec
Reputation Power: 8
FYI--new py2exe version released --0.6.2
The new version has a nifty option that can allow you to create a fast standalone executable. Other installer packages usually unzip the exe into a temp dir and run it from there. The py2exe implementation does not.
You can bundle all of the files into a "Library.zip" and have a small executable, or bundle all into one .exe .
To create one large exe,simply add the line
Code:
zipfile=None
to your setup.py.
Then from the command line, call
Code:
python setup.py py2exe --bundle 1
The bundle 2 option, also does a little less bundling.
Posts: 350
Time spent in forums: 2 Days 11 h 53 m 20 sec
Reputation Power: 26
I found this little gem in
C:\Python24\Lib\site-packages\py2exe\samples\singlefile\gui\setup.py
on my computer after installing version 6.3 of Py2Exe. It creates a single executable file from wxPython code. I modified it slightly, added more user comments and called it wxPython2Exe.py .
Code:
# Py2Exe version 6.3 setup file for wxPython GUI programs.
# Creates a single exe file.
# It's easiest to add this wxPython2Exe.py file into the same
# folder with the source file and an optional iconfile like "icon.ico"
# (if you add your own icon file, remove the comment in front of icon_resources).
# Simply change the filename to whatever you called your source file.
# Optionally edit the version info and add the name of your icon file.
# Now run wxPython2Exe.py ...
# Two subfolders will be created called build and dist.
# The dist folder contains your .exe file, MSVCR71.dll and w9xpopen.exe
# Your .exe file contains your code, all neded modules and the Python interpreter.
# The MSVCR71.dll can be distributed, but is often already in the system32 folder.
from distutils.core import setup
import py2exe
import sys
# enter the filename of your wxPython code file to compile ...
filename = "wxCalc1.py"
# ... this creates the filename of your .exe file in the dist folder
if filename.endswith(".py"):
distribution = filename[:-3]
elif filename.endswith(".pyw"):
distribution = filename[:-4]
# if run without args, build executables in quiet mode
if len(sys.argv) == 1:
sys.argv.append("py2exe")
sys.argv.append("-q")
class Target:
def __init__(self, **kw):
self.__dict__.update(kw)
# for the versioninfo resources, edit to your needs
self.version = "0.6.3"
self.company_name = "My Company"
self.copyright = "no copyright"
self.name = "WxPython Calculator"
################################################################
# The manifest will be inserted as resource into your .exe. This
# gives the controls the Windows XP appearance (if run on XP ;-)
#
# Another option would be to store it in a file named
# test_wx.exe.manifest, and copy it with the data_files option into
# the dist-dir.
#
manifest_template = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="5.0.0.0"
processorArchitecture="x86"
name="%(prog)s"
type="win32"
/>
<description>%(prog)s Program</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
'''
RT_MANIFEST = 24
# description is the versioninfo resource
# script is the wxPython code file
# manifest_template is the above XML code
# distribution will be the exe filename
# icon_resource is optional, remove any comment and give it an iconfile you have
# otherwise a default icon is used
# dest_base will be the exe filename
test_wx = Target(
description = "A GUI app",
script = filename,
other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog=distribution))],
#icon_resources = [(1, "icon.ico")],
dest_base = distribution)
################################################################
setup(
options = {"py2exe": {"compressed": 1,
"optimize": 2,
"ascii": 1,
"bundle_files": 1}},
zipfile = None,
windows = [test_wx],
)
Last edited by Dietrich : January 21st, 2006 at 02:59 PM.