cpython/Tools/freeze
Guido van Rossum a0e18357e7 Rearrange some stuff so that the warning for unknown modules is also
issued on Windows.
1998-03-07 04:51:03 +00:00
..
README Added Windows NT instructions. 1997-08-14 02:12:04 +00:00
checkextensions.py Lots of things added. README written (mostly). 1994-10-05 16:13:01 +00:00
freeze.py Rearrange some stuff so that the warning for unknown modules is also 1998-03-07 04:51:03 +00:00
hello.py initial checkin 1994-10-08 19:30:50 +00:00
makeconfig.py Totally new "freeze" program. 1994-10-03 16:33:08 +00:00
makefreeze.py Reindented, removed tabs. 1998-03-05 04:56:37 +00:00
makemakefile.py Reindented, removed tabs. 1998-03-05 05:22:36 +00:00
modulefinder.py Always set the __file__ attribute, so dynamic link modules are indicated. 1998-03-06 19:55:10 +00:00
parsesetup.py Totally new "freeze" program. 1994-10-03 16:33:08 +00:00
winmakemakefile.py Got rid of the last tab character in this file. 1998-03-06 19:55:36 +00:00

README

THE FREEZE SCRIPT
=================

(Directions for Windows NT are at the end of this file.)


What is Freeze?
---------------

Freeze make it possible to ship arbitrary Python programs to people
who don't have Python.  The shipped file (called a "frozen" version of
your Python program) is an executable, so this only works if your
platform is compatible with that on the receiving end (this is usually
a matter of having the same major operating system revision and CPU
type).

The shipped file contains a Python interpreter and large portions of
the Python run-time.  Some measures have been taken to avoid linking
unneeded modules, but the resulting binary is usually not small.

The Python source code of your program (and of the library modules
written in Python that it uses) is not included in the binary --
instead, the compiled byte-code (the instruction stream used
internally by the interpreter) is incorporated.  This gives some
protection of your Python source code, though not much -- a
disassembler for Python byte-code is available in the standard Python
library.  At least someone running "strings" on your binary won't see
the source.


How does Freeze know which modules to include?
----------------------------------------------

Freeze uses a pretty simple-minded algorithm to find the modules that
your program uses: given a file containing Python source code, it
scans for lines beginning with the word "import" or "from" (possibly
preceded by whitespace) and then it knows where to find the module
name(s) in those lines.  It then recursively scans the source for
those modules (if found, and not already processed) in the same way.

Freeze will not see import statements hidden behind another statement,
like this:

	if some_test: import M  # M not seen

or like this:

	import A; import B; import C  # B and C not seen

nor will it see import statements constructed using string
operations and passed to 'exec', like this:

	exec "import %s" % "M"  # M not seen

On the other hand, Freeze will think you are importing a module even
if the import statement it sees will never be executed, like this:

	if 0:
		import M  # M is seen

One tricky issue: Freeze assumes that the Python interpreter and
environment you're using to run Freeze is the same one that would be
used to run your program, which should also be the same whose sources
and installed files you will learn about in the next section.  In
particular, your PYTHONPATH setting should be the same as for running
your program locally.  (Tip: if the program doesn't run when you type
"python hello.py" there's little chance of getting the frozen version
to run.)


How do I use Freeze?
--------------------

Normally, you should be able to use it as follows:

	python freeze.py hello.py

where hello.py is your program and freeze.py is the main file of
Freeze (in actuality, you'll probably specify an absolute pathname
such as /usr/joe/python/Tools/freeze/freeze.py).


What do I do next?
------------------

Freeze creates three files: frozen.c, config.c and Makefile.  To
produce the frozen version of your program, you can simply type
"make".  This should produce a binary file.  If the filename argument
to Freeze was "hello.py", the binary will be called "hello".

Note: you can use the -o option to freeze to specify an alternative
directory where these files are created. This makes it easier to
clean up after you've shipped the frozen binary.


Troubleshooting
---------------

If you have trouble using Freeze for a large program, it's probably
best to start playing with a really simple program first (like the file
hello.py).  If you can't get that to work there's something
fundamentally wrong -- perhaps you haven't installed Python.  To do a
proper install, you should do "make install" in the Python root
directory.


Usage under Windows NT
----------------------

Under Windows NT, you *must* use the -p option and point it to the top
of the Python source tree.

WARNING: the resulting executable is not self-contained; it requires
the Python DLL, currently PYTHON15.DLL (it does not require the
standard library of .py files though).

The driver script generates a Makefile that works with the Microsoft
command line C compiler (CL).  To compile, run "nmake"; this will
build a target "hello.exe" if the source was "hello.py".  Only the
files frozenmain.c and frozen.c are used; no config.c is generated or
used, since the standard DLL is used.

In order for this to work, you must have built Python using the VC++
(Developer Studio) 5.0 compiler.  The provided project builds
python15.lib in the subdirectory pcbuild\Release of thje Python source
tree, and this is where the generated Makefile expects it to be.  If
this is not the case, you can edit the Makefile or (probably better)
winmakemakefile.py (e.g., if you are using the 4.2 compiler, the
python15.lib file is generated in the subdirectory vc40 of the Python
source tree).

Freezing pure GUI applications has not yet been tried; there's a new
-s option to specify the subsystem, but only the default ('console')
has been tested.  Freezing applications using Tkinter works; note that
these will require that that _tkinter.dll is available and the right
version of Tcl/Tk (the one that was used to build _tkinter.dll) is
installed.

--Guido van Rossum (home page: http://www.python.org/~guido/)