~ubuntu-branches/ubuntu/gutsy/pygame/gutsy

« back to all changes in this revision

Viewing changes to docs/tut/Executable.html

  • Committer: Bazaar Package Importer
  • Author(s): Ed Boraas
  • Date: 2002-02-20 06:39:24 UTC
  • Revision ID: james.westby@ubuntu.com-20020220063924-amlzj7tqkeods4eq
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--
 
2
TUTORIAL:Creating a Standalone Windows Executable
 
3
--><html><head>
 
4
 
 
5
<title>Pygame Tutorials - Creating Windows Executables</title>
 
6
</head><body>
 
7
 
 
8
<h1 align=center><font size=-1>Pygame Tutorials</font><br>Windows Executables</h1>
 
9
<h2 align=center>by Pete Shinners<br><font size=-1>pete@shinners.org</font></h2>
 
10
<h3 align=center>Revision 1.2, January 28th, 2002</h3>
 
11
<br><br>
 
12
 
 
13
 
 
14
<h2>Introduction</h2>
 
15
 
 
16
One drawback to creating your game with <b>pygame</b> is the large amount of
 
17
dependencies that your game requires. In order for people to play your game,
 
18
they need a lot of libraries installed. For unix users, this isn't too bad,
 
19
since most unix distributions come with their own package and dependency
 
20
management system. On Windows there is nothing like this, and it is more
 
21
difficult for a Windows user to just download your python source and run your
 
22
game.
 
23
<br>&nbsp;<br>
 
24
The best solution is to create a collection of all the needed files for your
 
25
game to run. With python this can mean a lot of files. This document will show
 
26
you the tools you need to create a standalone version of your game. It is not
 
27
difficult.
 
28
 
 
29
 
 
30
<br>&nbsp;<br>&nbsp;<br>
 
31
<h2>Download The Tools</h2>
 
32
The first thing you need to do is download the tools to build the executable.
 
33
We will use the excellent <tt>
 
34
PY2EXE</tt> tool. This package extends the distutils to turn your python
 
35
code into an executable. You can grab the latest version from the <tt>
 
36
<a href=http://starship.python.net/crew/theller/py2exe/index.html>PY2EXE</a></tt>
 
37
page. It uses a simple windows installer to manage the installation.
 
38
<br>&nbsp;<br>
 
39
To use <tt>PY2EXE</tt> you'll need to create a simple distutils script to
 
40
run it. I've created a version of this script that I suggest you use. 
 
41
<tt><a href=http://pygame.seul.org/ftp/pygame2exe.py>pygame2exe.py</a></tt>.
 
42
 
 
43
<br>&nbsp;<br>&nbsp;<br>
 
44
<h2>Build the Script</h2>
 
45
There's a small block of variables you will want to change in the <tt>pygame2exe.py</tt>
 
46
script to make it work for your specific game.
 
47
<pre>
 
48
project_name = "aliens"         #name for exe
 
49
project_script = "aliens.py"    #name of base .PY
 
50
icon_file = "aliens.ico"        #name of .ICO
 
51
optimize = 2                    #0, 1, or 2; like -O and -OO
 
52
dos_console = 0                 #set to 1 to run in a DOS box
 
53
data_directories = ['data']     #used data directories
 
54
extra_modules = []              #any extra modules that are missing
 
55
</pre>
 
56
 
 
57
Most of the options are pretty self descriptive. When first testing your game,
 
58
you'll want to set the <tt>dos_console</tt> value to 1. This will print any
 
59
errors into the dos console. When you release your game, you'll want to set it
 
60
back to 0, so your game can run without opening a dos prompt.
 
61
<br>&nbsp;<br>
 
62
 
 
63
If you notice your game doesn't run, and get an error about missing modules,
 
64
you can add the names of specific missing modules to the list named <tt>
 
65
extra_modules</tt>. For example, if your game uses the surfarray module, 
 
66
surfarray depends on the Numeric modules, but sometimes it can be difficult for
 
67
<tt>PY2EXE</tt> to detect Numeric as a dependency. You can add the missing Numeric
 
68
modules to this list and everything will be ok.
 
69
<br>&nbsp;<br>
 
70
 
 
71
Once you are all setup, simply run this script and it will do all the work.
 
72
The final executable and DLLs will be placed inside a project directory, which
 
73
will be inside a directory named "<tt>dist</tt>".
 
74
<br>&nbsp;<br>
 
75
 
 
76
You'll notice there aren't any .PY source files in the final directory. That is
 
77
because all the needed python source has been compressed as bytecode into the
 
78
actual executable file.
 
79
<br>&nbsp;<br>
 
80
 
 
81
The <tt>icon_file</tt> variable is an optional name of a .ICO file to use
 
82
for the executable. You can leave it empty ("") and it will be ignored.
 
83
Also be warned the icon_file doesn't work too well, especially on windows9x.
 
84
<br>&nbsp;<br>
 
85
 
 
86
The <tt>data_directories</tt> is a list of paths that will be copies into
 
87
the final game directory. Since most games out there will require some
 
88
sort of graphics/sound/font resources, this will help copy them into the
 
89
correct place.
 
90
<br>&nbsp;<br>
 
91
 
 
92
You'll need to doublecheck that all the game resources and files got copied
 
93
into the final directory in the "dist" folder. Once that is done and the game
 
94
is working, you can compress the entire directory into a .ZIP file and send it
 
95
to all your friends. They do not need any versions of python or SDL installed on
 
96
their machines. Even if they have older versions of python </i>(like version
 
97
1.5.2)</i>, it will not interfere with your game.
 
98
<br>&nbsp;<br>
 
99
 
 
100
You can also safely pick through the final game directory, and remove any
 
101
of the "PYD" files that you don't expect your game to use. for example, if
 
102
you don't use joysticks in your game, you can remove the "joystick.pyd"
 
103
to make your game size a little smaller.
 
104
 
 
105
 
 
106
<br>&nbsp;<br>&nbsp;<br>
 
107
<h2>Creating an Actual Installer</h2>
 
108
There's nothing wrong with distributing your game in a .ZIP file. But it is
 
109
usually a lot nicer to create an installer executable so the game can
 
110
automatically decompress itself, as well as setup Start Menu icons and adding
 
111
an option to uninstall. For this you'll need to use one of the many available
 
112
installing tools for windows. There are many free ones to choose from, and there
 
113
are several high quality ones.
 
114
<br>&nbsp;<br>
 
115
I can recommend <a href=http://www.jrsoftware.org/isinfo.htm>INNO Setup</a>
 
116
for creating the install tool, and <a href=http://www.bhenden.org/istool>
 
117
ISTool</a> for configuring the package. These are both of the utilities I use
 
118
when creating the installable pygame package for windows.
 
119