blob: 5617eeec164c61045389f8050d2311c414f4c906 [file] [log] [blame]
Guido van Rossumd8336c21994-10-05 16:13:01 +00001THE FREEZE SCRIPT
2=================
3
Guido van Rossumcef85a21998-03-07 04:51:54 +00004(Directions for Windows are at the end of this file.)
Guido van Rossum7ba3de41997-08-14 02:12:04 +00005
Guido van Rossumd8336c21994-10-05 16:13:01 +00006
7What is Freeze?
8---------------
9
10Freeze make it possible to ship arbitrary Python programs to people
11who don't have Python. The shipped file (called a "frozen" version of
12your Python program) is an executable, so this only works if your
13platform is compatible with that on the receiving end (this is usually
14a matter of having the same major operating system revision and CPU
15type).
16
17The shipped file contains a Python interpreter and large portions of
18the Python run-time. Some measures have been taken to avoid linking
19unneeded modules, but the resulting binary is usually not small.
20
21The Python source code of your program (and of the library modules
22written in Python that it uses) is not included in the binary --
23instead, the compiled byte-code (the instruction stream used
24internally by the interpreter) is incorporated. This gives some
25protection of your Python source code, though not much -- a
26disassembler for Python byte-code is available in the standard Python
27library. At least someone running "strings" on your binary won't see
28the source.
29
30
31How does Freeze know which modules to include?
32----------------------------------------------
33
Guido van Rossumcef85a21998-03-07 04:51:54 +000034Previous versions of Freeze used a pretty simple-minded algorithm to
35find the modules that your program uses, essentially searching for
36lines starting with the word "import". It was pretty easy to trick it
37into making mistakes, either missing valid import statements, or
38mistaking string literals (e.g. doc strings) for import statements.
Guido van Rossumd8336c21994-10-05 16:13:01 +000039
Guido van Rossumcef85a21998-03-07 04:51:54 +000040This has been remedied: Freeze now uses the regular Python parser to
41parse the program (and all its modules) and scans the generated byte
42code for IMPORT instructions. It may still be confused -- it will not
43know about calls to the __import__ built-in function, or about import
44statements constructed on the fly and executed using the 'exec'
45statement, and it will consider import statements even when they are
46unreachable (e.g. "if 0: import foobar").
Guido van Rossumd8336c21994-10-05 16:13:01 +000047
Guido van Rossumcef85a21998-03-07 04:51:54 +000048This new version of Freeze also knows about Python's new package
49import mechanism, and uses exactly the same rules to find imported
50modules and packages. One exception: if you write 'from package
51import *', Python will look into the __all__ variable of the package
52to determine which modules are to be imported, while Freeze will do a
53directory listing.
Guido van Rossumd8336c21994-10-05 16:13:01 +000054
55One tricky issue: Freeze assumes that the Python interpreter and
56environment you're using to run Freeze is the same one that would be
57used to run your program, which should also be the same whose sources
58and installed files you will learn about in the next section. In
59particular, your PYTHONPATH setting should be the same as for running
60your program locally. (Tip: if the program doesn't run when you type
61"python hello.py" there's little chance of getting the frozen version
62to run.)
63
64
65How do I use Freeze?
66--------------------
67
Guido van Rossum96c4dd91996-08-26 05:14:20 +000068Normally, you should be able to use it as follows:
Guido van Rossumd8336c21994-10-05 16:13:01 +000069
70 python freeze.py hello.py
71
72where hello.py is your program and freeze.py is the main file of
73Freeze (in actuality, you'll probably specify an absolute pathname
Guido van Rossum96c4dd91996-08-26 05:14:20 +000074such as /usr/joe/python/Tools/freeze/freeze.py).
Guido van Rossumd8336c21994-10-05 16:13:01 +000075
Guido van Rossumd8336c21994-10-05 16:13:01 +000076
Guido van Rossumd8336c21994-10-05 16:13:01 +000077What do I do next?
78------------------
79
Guido van Rossumbaf06031998-08-25 14:06:55 +000080Freeze creates a number of files: frozen.c, config.c and Makefile,
81plus one file for each Python module that gets included named
82M_<module>.c. To produce the frozen version of your program, you can
83simply type "make". This should produce a binary file. If the
84filename argument to Freeze was "hello.py", the binary will be called
85"hello".
Guido van Rossum96c4dd91996-08-26 05:14:20 +000086
87Note: you can use the -o option to freeze to specify an alternative
88directory where these files are created. This makes it easier to
Guido van Rossumcef85a21998-03-07 04:51:54 +000089clean up after you've shipped the frozen binary. You should invoke
90"make" in the given directory.
91
92
93Freezing Tkinter programs
94-------------------------
95
96Unfortunately, it is currently not possible to freeze programs that
97use Tkinter. It *seems* to work, but when you ship the frozen program
98to a site without a Tcl/Tk installation, it will fail with a complaint
99about missing Tcl/Tk initialization files.
100
101A workaround would be possible, in which the Tcl/Tk library files are
102incorporated in a frozen Python module as string literals and written
103to a temporary location when the program runs; this is currently left
104as an exercise for the reader. (If you implement this, please post to
105the Python newsgroup!)
106
107Of course, you can also simply require that Tcl/Tk is required on the
108target installation.
109
110
111A warning against shared library modules
112----------------------------------------
113
114When your Python installation uses shared library modules, these will
115not be incorporated in the frozen program. Again, the frozen program
116will work when you test it, but it won't work when you ship it to a
117site without a Python installation.
118
119Freeze prints a warning when this is the case at the end of the
120freezing process:
121
122 Warning: unknown modules remain: ...
123
124When this occurs, the best thing to do is usually to rebuild Python
125using static linking only.
Guido van Rossumd8336c21994-10-05 16:13:01 +0000126
127
Guido van Rossumbf6bdb01995-04-05 10:59:20 +0000128Troubleshooting
129---------------
Guido van Rossumd8336c21994-10-05 16:13:01 +0000130
Guido van Rossumbf6bdb01995-04-05 10:59:20 +0000131If you have trouble using Freeze for a large program, it's probably
Guido van Rossum96c4dd91996-08-26 05:14:20 +0000132best to start playing with a really simple program first (like the file
133hello.py). If you can't get that to work there's something
134fundamentally wrong -- perhaps you haven't installed Python. To do a
135proper install, you should do "make install" in the Python root
136directory.
Guido van Rossumbf6bdb01995-04-05 10:59:20 +0000137
138
Guido van Rossumcef85a21998-03-07 04:51:54 +0000139Usage under Windows 95 or NT
140----------------------------
Guido van Rossum7ba3de41997-08-14 02:12:04 +0000141
Guido van Rossumcef85a21998-03-07 04:51:54 +0000142Under Windows 95 or NT, you *must* use the -p option and point it to
143the top of the Python source tree.
Guido van Rossum7ba3de41997-08-14 02:12:04 +0000144
145WARNING: the resulting executable is not self-contained; it requires
146the Python DLL, currently PYTHON15.DLL (it does not require the
Guido van Rossumcef85a21998-03-07 04:51:54 +0000147standard library of .py files though). It may also require one or
148more extension modules loaded from .DLL or .PYD files; the module
149names are printed in the warning message about remaining unknown
150modules.
Guido van Rossum7ba3de41997-08-14 02:12:04 +0000151
152The driver script generates a Makefile that works with the Microsoft
153command line C compiler (CL). To compile, run "nmake"; this will
154build a target "hello.exe" if the source was "hello.py". Only the
155files frozenmain.c and frozen.c are used; no config.c is generated or
156used, since the standard DLL is used.
157
158In order for this to work, you must have built Python using the VC++
159(Developer Studio) 5.0 compiler. The provided project builds
160python15.lib in the subdirectory pcbuild\Release of thje Python source
161tree, and this is where the generated Makefile expects it to be. If
162this is not the case, you can edit the Makefile or (probably better)
163winmakemakefile.py (e.g., if you are using the 4.2 compiler, the
164python15.lib file is generated in the subdirectory vc40 of the Python
165source tree).
166
Guido van Rossumcef85a21998-03-07 04:51:54 +0000167You can freeze programs that use Tkinter, but Tcl/Tk must be installed
168on the target system.
169
170It is possible to create frozen programs that don't have a console
171window, by specifying the option '-s windows'.
Guido van Rossum7ba3de41997-08-14 02:12:04 +0000172
Guido van Rossum96c4dd91996-08-26 05:14:20 +0000173--Guido van Rossum (home page: http://www.python.org/~guido/)