blob: 32c745873f44227efe82bcce2125a19a9c58ea64 [file] [log] [blame]
Guido van Rossumd8336c21994-10-05 16:13:01 +00001THE FREEZE SCRIPT
2=================
3
4
5What is Freeze?
6---------------
7
8Freeze make it possible to ship arbitrary Python programs to people
9who don't have Python. The shipped file (called a "frozen" version of
10your Python program) is an executable, so this only works if your
11platform is compatible with that on the receiving end (this is usually
12a matter of having the same major operating system revision and CPU
13type).
14
15The shipped file contains a Python interpreter and large portions of
16the Python run-time. Some measures have been taken to avoid linking
17unneeded modules, but the resulting binary is usually not small.
18
19The Python source code of your program (and of the library modules
20written in Python that it uses) is not included in the binary --
21instead, the compiled byte-code (the instruction stream used
22internally by the interpreter) is incorporated. This gives some
23protection of your Python source code, though not much -- a
24disassembler for Python byte-code is available in the standard Python
25library. At least someone running "strings" on your binary won't see
26the source.
27
28
29How does Freeze know which modules to include?
30----------------------------------------------
31
32Freeze uses a pretty simple-minded algorithm to find the modules that
33your program uses: given a file containing Python source code, it
34scans for lines beginning with the word "import" or "from" (possibly
35preceded by whitespace) and then it knows where to find the module
36name(s) in those lines. It then recursively scans the source for
37those modules (if found, and not already processed) in the same way.
38
39Freeze will not see import statements hidden behind another statement,
40like this:
41
42 if some_test: import M # M not seen
43
44or like this:
45
46 import A; import B; import C # B and C not seen
47
48nor will it see import statements constructed using string
49operations and passed to 'exec', like this:
50
51 exec "import %s" % "M" # M not seen
52
53On the other hand, Freeze will think you are importing a module even
54if the import statement it sees will never be executed, like this:
55
56 if 0:
57 import M # M is seen
58
59One tricky issue: Freeze assumes that the Python interpreter and
60environment you're using to run Freeze is the same one that would be
61used to run your program, which should also be the same whose sources
62and installed files you will learn about in the next section. In
63particular, your PYTHONPATH setting should be the same as for running
64your program locally. (Tip: if the program doesn't run when you type
65"python hello.py" there's little chance of getting the frozen version
66to run.)
67
68
69How do I use Freeze?
70--------------------
71
Guido van Rossum96c4dd91996-08-26 05:14:20 +000072Normally, you should be able to use it as follows:
Guido van Rossumd8336c21994-10-05 16:13:01 +000073
74 python freeze.py hello.py
75
76where hello.py is your program and freeze.py is the main file of
77Freeze (in actuality, you'll probably specify an absolute pathname
Guido van Rossum96c4dd91996-08-26 05:14:20 +000078such as /usr/joe/python/Tools/freeze/freeze.py).
Guido van Rossumd8336c21994-10-05 16:13:01 +000079
Guido van Rossum96c4dd91996-08-26 05:14:20 +000080(With Python 1.4, freeze is much more likely to work "out of the box"
81than before, provided Python has been installed properly.)
Guido van Rossumd8336c21994-10-05 16:13:01 +000082
83
Guido van Rossumd8336c21994-10-05 16:13:01 +000084What do I do next?
85------------------
86
87Freeze creates three files: frozen.c, config.c and Makefile. To
88produce the frozen version of your program, you can simply type
89"make". This should produce a binary file. If the filename argument
Guido van Rossum96c4dd91996-08-26 05:14:20 +000090to Freeze was "hello.py", the binary will be called "hello".
91
92Note: you can use the -o option to freeze to specify an alternative
93directory where these files are created. This makes it easier to
94clean up after you've shipped the frozen binary.
Guido van Rossumd8336c21994-10-05 16:13:01 +000095
96
Guido van Rossumbf6bdb01995-04-05 10:59:20 +000097Troubleshooting
98---------------
Guido van Rossumd8336c21994-10-05 16:13:01 +000099
Guido van Rossumbf6bdb01995-04-05 10:59:20 +0000100If you have trouble using Freeze for a large program, it's probably
Guido van Rossum96c4dd91996-08-26 05:14:20 +0000101best to start playing with a really simple program first (like the file
102hello.py). If you can't get that to work there's something
103fundamentally wrong -- perhaps you haven't installed Python. To do a
104proper install, you should do "make install" in the Python root
105directory.
Guido van Rossumbf6bdb01995-04-05 10:59:20 +0000106
107
Guido van Rossum96c4dd91996-08-26 05:14:20 +0000108--Guido van Rossum (home page: http://www.python.org/~guido/)