py2exe
distutils
helps you package your Python extensions and applications. However, an end user 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 prove too much of a hassle for such end users.
Thomas Heller has developed a simple solution, a distutils
add-on named py2exe
, freely available for download from http://starship.python.net/crew/theller/py2exe/. This URL also contains detailed documentation of py2exe
, and I recommend you study this documentation if you intend to use py2exe
in advanced ways. However, the simplest uses, which I cover in the rest of this section, cover most practical needs.
After downloading and installing py2exe
(on a Windows machine where Microsoft VS 2003 is also installed), you just need to add the line:
import py2exe
at the start of your otherwise normal distutils
script setup.py. Now, in addition to other distutils
commands, you have one more option. Running:
python setup.py py2exe
builds and collects in a subdirectory of your distribution root directory an .exe file and one or more .dll files. If your distribution’s name
metadata is, for example, myapp
, then the directory into which the .exe and .dll files are collected is named dist\myapp\. Any files specified by option data_files
in your setup.py script are placed in subdirectories ...
Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.