.exe
. It will also find any
DLLs your script depends on and copy them too. This means Python and all
the related libraries don't have to be installed on your presentation
machine you just unzip a directory, double-click the
.exe
file, and go.Here I will go over the steps you need to take your script and package it up. I will assume that your presentation directory is structured something like this:
mytalk/ mainscript.py <-- the main presentation script sub1.py sub2.py gldiagram.pyd . . . fonts/ whatever.pfb other.ttf foo.slf . . . images/ foo.jpg bar.tga baz.gif qux.png movie.avi
That is, all your scripts and OpenGL diagrams (if any) are in the main directory, and there are subdirectories containing other files (fonts and images) loaded by your presentation.
It's not essential that your presentation looks exactly like this. What is essential is that all images and font files are loaded using relative paths, not absolute paths. Once it's rolled up into an EXE, you won't be able to go in and change these, so make sure they are specified relative to the location of the main script!
Run through your presentation to confirm that it works. Once you're ready you can begin the packaging process:
c:\python22\lib\site-packages\Pmw\Pmw_1_1\bin
.
(Assuming python is installed in the default c:\python22
;
change the paths if you installed Python somewhere else.
python bundlepmw.py
c:\python22\lib\site-packages\Pmw\Pmw_1_1\lib
". This will
create a file called "Pmw.py
" in the current directory.
Pmw.py
" to your main script directory.
..\lib\PmwBlt.py
" and
"..\lib\PmwColor.py
" to your main script directory, too.
At the top of your main script, add a blob of code that looks like this:
import Image import JpegImagePlugin # import drivers for every image format you use import TgaImagePlugin import PngImagePlugin import GifImagePlugin Image._initialized = 1
This will force the import of the formats you list. You need to load the plugins for every image type that's used in your presentation. Here's the complete list of available plugins:
ArgImagePlugin | BmpImagePlugin | CurImagePlugin |
DcxImagePlugin | EpsImagePlugin | FliImagePlugin |
FpxImagePlugin | GbrImagePlugin | GifImagePlugin |
IcoImagePlugin | ImImagePlugin | ImtImagePlugin |
IptcImagePlugin | JpegImagePlugin | McIdasImagePlugin |
MicImagePlugin | MpegImagePlugin | MspImagePlugin |
PcdImagePlugin | PcxImagePlugin | PdfImagePlugin |
PixarImagePlugin | PngImagePlugin | PpmImagePlugin |
PsdImagePlugin | SgiImagePlugin | SunImagePlugin |
TgaImagePlugin | TiffImagePlugin | WmfImagePlugin |
XVThumbImagePlugin | XbmImagePlugin | XpmImagePlugin |
setup.py
that contains the
following:
from distutils.core import setup
import py2exe
setup(name="presentation",
scripts=["mainscript.py"], # put the name of your main script here
)
% python setup.py py2exe
It prints lots of stuff as it searches for dependencies, byte-compiles
files, etc. You'll probably get a warning at the end about it not
locating the "os.path
" module, but this is harmless.
When it finishes, your directory structure will look like this:
mytalk/
mainscript.py <-- the main presentation script
. . .
fonts/
. . .
images/
. . .
build/ # all this is created by running setup.py
. . .
dist/
mainscript/
mainscript.exe
*.dll
*.pyd
The leftover build
directory is superfluous; you
can ignore it or delete it if you like.
mainscript
directory, making sure they're in the same position relative to
mainscript.exe
that they were to
mainscript.py
. Here's what my example looks like after
the copy:
mytalk/
mainscript.py <-- the main presentation script
. . .
fonts/
. . .
images/
. . .
build/
. . .
dist/
mainscript/ # zip up this part of the tree
mainscript.exe # to create a portable presentation
*.dll
*.pyd
fonts/ <-- copy of the original fonts dir
. . .
images/ <-- copy of the original images dir
. . .
If you're planning to distribute your presentation, keep in mind the legal implications of distributing scalable outline font files. You may want to use Slithy's own image-based font format so as to avoid distributing TTF and PFB files.
mainscript
directory and run
mainscript.exe
to display your presentation. After
confirming that it works, zip up the entire mainscript
directory (the boldface part of the tree above.) This is your whole
presentation, and should work even on machines without Python
installed.