blob: 1bc864beef6ec45a998aecfdfbf1524e4450345d [file] [log] [blame]
Guido van Rossumd8336c21994-10-05 16:13:01 +00001THE FREEZE SCRIPT
2=================
3
Guido van Rossum7ba3de41997-08-14 02:12:04 +00004(Directions for Windows NT are at the end of this file.)
5
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
34Freeze uses a pretty simple-minded algorithm to find the modules that
35your program uses: given a file containing Python source code, it
36scans for lines beginning with the word "import" or "from" (possibly
37preceded by whitespace) and then it knows where to find the module
38name(s) in those lines. It then recursively scans the source for
39those modules (if found, and not already processed) in the same way.
40
41Freeze will not see import statements hidden behind another statement,
42like this:
43
44 if some_test: import M # M not seen
45
46or like this:
47
48 import A; import B; import C # B and C not seen
49
50nor will it see import statements constructed using string
51operations and passed to 'exec', like this:
52
53 exec "import %s" % "M" # M not seen
54
55On the other hand, Freeze will think you are importing a module even
56if the import statement it sees will never be executed, like this:
57
58 if 0:
59 import M # M is seen
60
61One tricky issue: Freeze assumes that the Python interpreter and
62environment you're using to run Freeze is the same one that would be
63used to run your program, which should also be the same whose sources
64and installed files you will learn about in the next section. In
65particular, your PYTHONPATH setting should be the same as for running
66your program locally. (Tip: if the program doesn't run when you type
67"python hello.py" there's little chance of getting the frozen version
68to run.)
69
70
71How do I use Freeze?
72--------------------
73
Guido van Rossum96c4dd91996-08-26 05:14:20 +000074Normally, you should be able to use it as follows:
Guido van Rossumd8336c21994-10-05 16:13:01 +000075
76 python freeze.py hello.py
77
78where hello.py is your program and freeze.py is the main file of
79Freeze (in actuality, you'll probably specify an absolute pathname
Guido van Rossum96c4dd91996-08-26 05:14:20 +000080such as /usr/joe/python/Tools/freeze/freeze.py).
Guido van Rossumd8336c21994-10-05 16:13:01 +000081
Guido van Rossumd8336c21994-10-05 16:13:01 +000082
Guido van Rossumd8336c21994-10-05 16:13:01 +000083What do I do next?
84------------------
85
86Freeze creates three files: frozen.c, config.c and Makefile. To
87produce the frozen version of your program, you can simply type
88"make". This should produce a binary file. If the filename argument
Guido van Rossum96c4dd91996-08-26 05:14:20 +000089to Freeze was "hello.py", the binary will be called "hello".
90
91Note: you can use the -o option to freeze to specify an alternative
92directory where these files are created. This makes it easier to
93clean up after you've shipped the frozen binary.
Guido van Rossumd8336c21994-10-05 16:13:01 +000094
95
Guido van Rossumbf6bdb01995-04-05 10:59:20 +000096Troubleshooting
97---------------
Guido van Rossumd8336c21994-10-05 16:13:01 +000098
Guido van Rossumbf6bdb01995-04-05 10:59:20 +000099If you have trouble using Freeze for a large program, it's probably
Guido van Rossum96c4dd91996-08-26 05:14:20 +0000100best to start playing with a really simple program first (like the file
101hello.py). If you can't get that to work there's something
102fundamentally wrong -- perhaps you haven't installed Python. To do a
103proper install, you should do "make install" in the Python root
104directory.
Guido van Rossumbf6bdb01995-04-05 10:59:20 +0000105
106
Guido van Rossum7ba3de41997-08-14 02:12:04 +0000107Usage under Windows NT
108----------------------
109
110Under Windows NT, you *must* use the -p option and point it to the top
111of the Python source tree.
112
113WARNING: the resulting executable is not self-contained; it requires
114the Python DLL, currently PYTHON15.DLL (it does not require the
115standard library of .py files though).
116
117The driver script generates a Makefile that works with the Microsoft
118command line C compiler (CL). To compile, run "nmake"; this will
119build a target "hello.exe" if the source was "hello.py". Only the
120files frozenmain.c and frozen.c are used; no config.c is generated or
121used, since the standard DLL is used.
122
123In order for this to work, you must have built Python using the VC++
124(Developer Studio) 5.0 compiler. The provided project builds
125python15.lib in the subdirectory pcbuild\Release of thje Python source
126tree, and this is where the generated Makefile expects it to be. If
127this is not the case, you can edit the Makefile or (probably better)
128winmakemakefile.py (e.g., if you are using the 4.2 compiler, the
129python15.lib file is generated in the subdirectory vc40 of the Python
130source tree).
131
132Freezing pure GUI applications has not yet been tried; there's a new
133-s option to specify the subsystem, but only the default ('console')
134has been tested. Freezing applications using Tkinter works; note that
135these will require that that _tkinter.dll is available and the right
136version of Tcl/Tk (the one that was used to build _tkinter.dll) is
137installed.
138
Guido van Rossum96c4dd91996-08-26 05:14:20 +0000139--Guido van Rossum (home page: http://www.python.org/~guido/)