全部博文(2005)
分类: Python/Ruby
2008-12-17 10:35:48
The mcillian installer development is discontinued.
mirror:
Continued development(not tested yet):
This works on Win32.
Unzip the Installer in a directory of your choice, and cd there.
Configure the Installer by running:
python Configure.py
Python must be in your PATH for this to work, if it's not, type from the command prompt:
PATH=%PATH%;c:\python23
where c:\python23 must be replaced with the root of your python installation.
Then, assuming the source code is app.py (placed in c:\source):
python Makespec.py --upx --onefile --noconsole c:\source\app.py
python Build.py app\app.spec
Replace 'app' everywhere above with your application name.
You will end up with app\app.exe under the Installer dir.This is a one file .exe containing all the application.
If you don't want a one-file build, suppress the option --onefile above.
If you don't have installed (or don't want to use it), suppress the option --upx above.
The option --noconsole is needed to produce a windows gui application,
instead of a console one (so the command shell won't pop up when you
run the application).
[ More details to be written... ]
Create a setup.py script for using py2exe to generating the exe file. (The script to compile in this case is wxTail.py):
# setup.py
from distutils.core import setup
import py2exe
setup(name="wxTail",scripts=["wxTail.py"],)
Sample of the win32 command for running py2exe:
python setup.py py2exe
If you use the unicode version of wxpython you have to manually include the file unicows.dll form your python installation directory. Otherwise the application will crash at least on Windows 98.
--
[ More details to be written... ]
To turn your binary and accompanying library files into a Windows installer you can use:
innosetup from
NSIS from (and HM-NSIS-Edit for the wizard).
When using py2exe with pythoncom (or with wxPython's ActiveXWrapper which uses pythoncom) py2exe has trouble finding the code for the generated COM wrapper modules and you end up with import errors. Here is the solution, which was sent to the mail list by Clark C. Evans:
from wxPython.wx import *
if wxPlatform == '__WXMSW__':
from wxPython.lib.activexwrapper import MakeActiveXClass
import ie5
browserModule = ie5
Another work-around if you run into issues running py2exe compiled programs with the ActiveXWrapper controls (specifically the PDF Window control in wxPython 2.8) is to add a typelibs entry to the options argument in your setup.py file. See the sample setup.py below for an example.
from distutils.core import setup
import py2exe
manifest = """manifestVersion="1.0"> version="0.64.1.0"
processorArchitecture="x86"
name="Controls"
type="win32"
/>myProgram
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
"""
"""
installs manifest and icon into the .exe
but icon is still needed as we open it
for the window icon (not just the .exe)
changelog and logo are included in dist
"""
setup(
options = {'py2exe': {
'compressed': 1,
'optimize': 2,
'bundle_files': 3,
'typelibs' : [("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)],
}
},
windows = [
{
"script": "myprogram.py",
"icon_resources": [(1, "program.ico")],
"other_resources": [(24,1,manifest)],
}
],
data_files=["help.txt",
"program.ico",
"program.ini"],
)
Basically the typelibs line ensures py2exe picks up the dynamically imported module in pdfwin.py that is included with the Windows wxPython distribution.
_browserModule = win32com.client.gencache.EnsureModule(
"{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)
A binary distribution of a Python/wxPython program on Linux has these advantages:
cx_Freeze turns a Python script into a binary file and any referenced binary modules.
Download cx_Freeze from I recommend getting the binary distribution. If you extract it in /opt, then it will end up installed in /opt/cx_Freeze-2.1/ (this location is assumed through the rest of this document).
Also note that while cx_Freeze is free software, you do need to abide by the license agreement on the same page.
The wxPython shared libraries have some pathnames hardcoded into them (also known as an rpath). chrpath removes this hardcoded path for where other shared libraries are searched.
Download chrpath from By default it installs in /usr/local/bin which should be on your path.
Create a clean directory for the resulting files. I make one named dist.
Assuming the main entrypoint to your program is example.py, this is what you run:
$ cxpath=/opt/cx_Freeze-2.1
$ env PATH=$cxpath:$PATH FreezePython --install-dir=dist --base-binary=$cxpath/ConsoleSetLibPathBase example.py
Everything should end up in the dist subdirectory, and the main binary will be named dist/example
You now need to remove hard coded path information from the wxPython and other shared libraries. I use this shell script:
for i in *.so
do
if chrpath $i 2>/dev/null | grep = >/dev/null
then
echo "Fixing $i"
chrpath -d $i
fi
done
Change into the dist subdirectory and run the script. It should fix at least wxPython.wxc.so, and same other wx-controls you may use (eg calendar).
You can now just tar up the dist subdirectory. Users can place the contents anywhere they choose on the filesystem, and call the main executable for everything to work.
I normally put all the files in a subdirectory of /usr/lib (for example: /usr/lib/example-1.0 and then put a wrapper script in /usr/bin that execs the binary in /usr/lib/example-1.0.
The Python included with Mac OS X contains a tool called BundleBuilder.py which lets you package Python scripts into ".app" bundles that can be distributed on computers even without Python installed. (Although OS X 10.3 contains a complete implementation of Python.) Documentation on this tool (including an example of a wxPython app building script) can be found here:
The important part to note is that you must manually include the wxWindows dynamic libraries at this point. See the lines in the example script containing myapp.libs.append to see how to do so. Hopefully a more targeted and detailed tutorial will be forthcoming. =) In the meantime, please feel free to post your questions to either or .
The bitpim project produces Windows and Linux binary installers that don't require the user to have Python or wxPython installed (or even have to know what they are!)
Code is available in
makedist.py does the actual build an invokes the various other tools. bitpim.iss is the innosetup file. p2econfig.py is the py2exe file.