blob: 09a05d749aa0b4dba7f4c614db677c13194e72eb [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
80Freeze creates three files: frozen.c, config.c and Makefile. To
81produce the frozen version of your program, you can simply type
82"make". This should produce a binary file. If the filename argument
Guido van Rossum96c4dd91996-08-26 05:14:20 +000083to Freeze was "hello.py", the binary will be called "hello".
84
85Note: you can use the -o option to freeze to specify an alternative
86directory where these files are created. This makes it easier to
Guido van Rossumcef85a21998-03-07 04:51:54 +000087clean up after you've shipped the frozen binary. You should invoke
88"make" in the given directory.
89
90
91Freezing Tkinter programs
92-------------------------
93
94Unfortunately, it is currently not possible to freeze programs that
95use Tkinter. It *seems* to work, but when you ship the frozen program
96to a site without a Tcl/Tk installation, it will fail with a complaint
97about missing Tcl/Tk initialization files.
98
99A workaround would be possible, in which the Tcl/Tk library files are
100incorporated in a frozen Python module as string literals and written
101to a temporary location when the program runs; this is currently left
102as an exercise for the reader. (If you implement this, please post to
103the Python newsgroup!)
104
105Of course, you can also simply require that Tcl/Tk is required on the
106target installation.
107
108
109A warning against shared library modules
110----------------------------------------
111
112When your Python installation uses shared library modules, these will
113not be incorporated in the frozen program. Again, the frozen program
114will work when you test it, but it won't work when you ship it to a
115site without a Python installation.
116
117Freeze prints a warning when this is the case at the end of the
118freezing process:
119
120 Warning: unknown modules remain: ...
121
122When this occurs, the best thing to do is usually to rebuild Python
123using static linking only.
Guido van Rossumd8336c21994-10-05 16:13:01 +0000124
125
Guido van Rossumbf6bdb01995-04-05 10:59:20 +0000126Troubleshooting
127---------------
Guido van Rossumd8336c21994-10-05 16:13:01 +0000128
Guido van Rossumbf6bdb01995-04-05 10:59:20 +0000129If you have trouble using Freeze for a large program, it's probably
Guido van Rossum96c4dd91996-08-26 05:14:20 +0000130best to start playing with a really simple program first (like the file
131hello.py). If you can't get that to work there's something
132fundamentally wrong -- perhaps you haven't installed Python. To do a
133proper install, you should do "make install" in the Python root
134directory.
Guido van Rossumbf6bdb01995-04-05 10:59:20 +0000135
136
Guido van Rossumcef85a21998-03-07 04:51:54 +0000137Usage under Windows 95 or NT
138----------------------------
Guido van Rossum7ba3de41997-08-14 02:12:04 +0000139
Guido van Rossumcef85a21998-03-07 04:51:54 +0000140Under Windows 95 or NT, you *must* use the -p option and point it to
141the top of the Python source tree.
Guido van Rossum7ba3de41997-08-14 02:12:04 +0000142
143WARNING: the resulting executable is not self-contained; it requires
144the Python DLL, currently PYTHON15.DLL (it does not require the
Guido van Rossumcef85a21998-03-07 04:51:54 +0000145standard library of .py files though). It may also require one or
146more extension modules loaded from .DLL or .PYD files; the module
147names are printed in the warning message about remaining unknown
148modules.
Guido van Rossum7ba3de41997-08-14 02:12:04 +0000149
150The driver script generates a Makefile that works with the Microsoft
151command line C compiler (CL). To compile, run "nmake"; this will
152build a target "hello.exe" if the source was "hello.py". Only the
153files frozenmain.c and frozen.c are used; no config.c is generated or
154used, since the standard DLL is used.
155
156In order for this to work, you must have built Python using the VC++
157(Developer Studio) 5.0 compiler. The provided project builds
158python15.lib in the subdirectory pcbuild\Release of thje Python source
159tree, and this is where the generated Makefile expects it to be. If
160this is not the case, you can edit the Makefile or (probably better)
161winmakemakefile.py (e.g., if you are using the 4.2 compiler, the
162python15.lib file is generated in the subdirectory vc40 of the Python
163source tree).
164
Guido van Rossumcef85a21998-03-07 04:51:54 +0000165You can freeze programs that use Tkinter, but Tcl/Tk must be installed
166on the target system.
167
168It is possible to create frozen programs that don't have a console
169window, by specifying the option '-s windows'.
Guido van Rossum7ba3de41997-08-14 02:12:04 +0000170
Guido van Rossum96c4dd91996-08-26 05:14:20 +0000171--Guido van Rossum (home page: http://www.python.org/~guido/)