26.2 The py2exe Tool
help you package up your Python extensions and applications. However, an end
can install the resulting packaged form only after installing Python. This is particularly a problem on Windows, where end users want to run a single installer to get an application working on their machine. Installing Python first and then running your application's installer may
too much of a hassle for such end users.
Thomas Heller has developed a simple solution, a
available for download from http://starship.python.net/crew/theller/py2exe/. This URL also contains detailed documentation of
, and I recommend that you study that documentation if you intend to use
in advanced ways. However, the simplest kinds of use, which I cover in the rest of this section, cover most practical needs.
After downloading and installing
(on a Windows machine where Microsoft Visual C++ 6 is also installed), you just need to add the line:
at the start of your
. Now, in addition to other
commands, you have one more option. Running:
python setup.py py2exe
builds and collects in a subdirectory of your distribution root directory an
file and one or more
files. If your distribution's
metadata is, for example,
, then the directory into which the
files are collected is named
. Any files specified by option
script are placed in subdirectories of
file corresponds to your application's first or single entry in the
keyword argument value, and also contains the bytecode-compiled form of all Python modules and packages that your
specifies or implies. Among the
files is, at minimum, the Python dynamic load library, for example
if you use Python 2.2, plus any other
files that your application needs, excluding
are system files (i.e.,
to be available on any Windows installation).
provides no direct means to collect the contents of the
directory for easy distribution and installation. You have several options,
file (which may be given an
extension and made self-extracting, in ways that vary depending on the .
file handling tools you choose), all the way to a professional Windows installer construction system, such as those sold by companies such as Wise and InstallShield. One option that is particularly worth considering is Inno Setup, a free, professional-quality installer construction system (see http://www.jrsoftware.org/isinfo.php). Since the files to be packaged up for end user installation are an
file, one or more
files, and perhaps some data files in subdirectories, the issue becomes totally independent from Python. You may package up and redistribute such files just as if they had originally been built from sources written in any other programming language.