16.01.2014 Views

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

380 CHAPTER 18 ■ PACKAGING YOUR PROGRAMS<br />

You can run this script like this:<br />

python setup.py py2exe<br />

This will create a console application (called hello.exe) along with a couple of other files<br />

in the dist subdirec<strong>to</strong>ry. You can either run it from the command line or double-click it.<br />

More information on how py2exe works, and how you can use it in more advanced ways,<br />

can be found on the py2exe Web site (http://starship.python.net/crew/theller/py2exe).<br />

A Quick Summary<br />

Finally, you now know how <strong>to</strong> create shiny, professional-looking software with fancy GUI<br />

installers—or how <strong>to</strong> au<strong>to</strong>mate the generation of those precious .tar.gz files. Here is a summary<br />

of the specific concepts covered:<br />

Distutils. The Distutils <strong>to</strong>olkit lets you write installer scripts, conventionally called setup.py,<br />

which let you install modules, packages, and extensions, and which let you build distributable<br />

archives and simple Windows installers.<br />

Distutils commands. You can run your setup.py script with several commands, such as<br />

build, build_ext, install, sdist, and bdist.<br />

Installers. There are many installer genera<strong>to</strong>rs available, and you can use many of them <strong>to</strong><br />

install your <strong>Python</strong> programs, making the process easier for your users.<br />

Compiling extensions. You can use Distutils <strong>to</strong> have your C extensions compiled au<strong>to</strong>matically,<br />

with Distutils au<strong>to</strong>matically locating your <strong>Python</strong> installation and figuring out which<br />

compiler <strong>to</strong> use. You can even have it run SWIG au<strong>to</strong>matically.<br />

py2exe. The py2exe extension <strong>to</strong> Distutils can be used <strong>to</strong> create executable binaries from<br />

your <strong>Python</strong> programs. Along with a couple of extra files (which can be conveniently<br />

installed with an installer), these .exe files can be run without installing a <strong>Python</strong> interpreter<br />

separately.<br />

New Functions in This Chapter<br />

Function<br />

distutils.core.setup(...)<br />

Description<br />

Used <strong>to</strong> configure Distutils with keyword args in your<br />

setup.py scripts<br />

What Now?<br />

That’s it for the technical stuff—sort of. In the next chapter, you get some programming methodology<br />

and philosophy, and then come the projects. Enjoy!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!