There are two ways to create a frozen application: through the CodeWarrior development environment or without any development environment. The former method is more versatile and may result in smaller binaries, because you can better customize what is included in your eventual application. The latter method builds an application by glueing together the various .slb shared libraries that come with a binary Python installation into a single file. This method of freezing, which does not require you to spend money on a development environment, is unique to MacPython, incidentally, on other platforms you will always need a C compiler and linker.
Mac:Tools:macfreeze:macfreeze.py
you are asked for the
script file, and you can select which type of freeze to do. The first
time you should always choose report only, which will produce a
listing of modules and where they are included from in the console
window. Macfreeze actually parses all modules, so it may crash in the
process. If it does try again with a higher debug value, this should
show you where it crashes.
For more elaborate programs you will often see that freeze includes
modules you don't need (because they are for a different platform, for
instance) or that it cannot find all your modules (because you modify
sys.path
early in your initialization). It is possible to
include directives to tell macfreeze to add items to the search path and
include or exclude certain modules. All your directives should be in the
main script file.
Directives have the following form:
# macfreeze: command argumentThe trigger
macfreeze:
must be spelled exactly like that,
but the whitespace can be any combination of spaces and tabs. Macfreeze
understands the following directives:
path
sys.path
. The argument is a
pathname, which should probably be relative (starting with a colon) and
is interpreted relative to the folder where the script lives.
include
exclude
PYC
resources. This may be useful if you have embedded Python in your own
application. The resource file generated is the same as for the CodeWarrior
generation process.
.py
removed and
build.
prepended. If the output folder does not exist yet
it is created, and a template project file and bundle resource file are
deposited there. Next, a source file macfreezeconfig.c
is
created which includes all builtin modules your script uses, and a
resource file frozenmodules.rsrc
which contains the
PYC
resources for all your Python modules.
The project expects to live in a folder one level below the Python root
folder, so the next thing you should do is move the build folder there.
It is a good idea to leave an alias with the same name in the original
location: when you run freeze again it will regenerate the
frozenmodules.rsrc
file but not the project and bundle
files. This is probably what you want: if you modify your python sources
you have to re-freeze, but you may have changed the project and bundle
files, so you don't want to regenrate them.
An alternative is to leave the build folder where it is, but then you have to adapt the search path in the project.
The project is set up to include all the standard builtin modules, but the CW linker is smart enough to exclude any object code that isn't referenced. Still, it may be worthwhile to remove any sources for modules that you are sure are not used to cut back on compilation time. You may also want to examine the various resource files (for Tcl/Tk, for instance): the loader has no way to know that these aren't used.
You may also need to add sourcefiles if your script uses non-standard
builtin modules, like anything from the Extensions
folder.
The frozenbundle.rsrc
resource file contains the bundle
information. It is almost identical to the bundle file used for applets,
with the exception that it sets the sys.path
initialization
to $(APPLICATION)
only. This means that all modules will only
be looked for in PYC resources in your application.