bbfreeze is a Python module to create stand-alone executables from Python scripts. It's similar in purpose to the well known py2exe for windows, py2app for OS X, PyInstaller and cx_Freeze (in fact ancient versions were based on cx_Freeze. And it uses the modulegraph package, which is also used by py2app).
It has the following features:
easy installation
bbfreeze can be installed with setuptools' easy_install command.
zip/egg file import tracking
bbfreeze tracks imports from zip files and includes whole egg files if some module is used from an eggfile. Packages using setuputils' pkg_resources module will now work (new in 0.95.0)
binary dependency tracking
bbfreeze will track binary dependencies and will include DLLs and shared libraries needed by a frozen program.
multiple script freezing
bbfreeze can freeze multiple scripts at once.
python interpreter included
bbfreeze will create an extra executable named 'py', which might be used like the python executable itself.
automatic pathname rewriting
pathnames in tracebacks are replaced with relative pathnames (i.e. if you import package foo.bar from /home/jdoe/pylib/ tracebacks generated from functions in foo.bar will not show your local path /home/jdoe/pylib/foo/bar.py. They will instead show foo/bar.py)
distutils command 'bdist_bbfreeze'
A new distutils/setuptools command bdist_bbfreeze integrates bbfreeze into your setup.py.
bbfreeze works on windows and UNIX-like operating systems. bbfreeze has been tested with python 2.4, 2.5 and 2.6. bbfreeze will not work with python versions prior to 2.3 as it uses the zipimport feature introduced with python 2.3.
Installation
You need to have setuptools/easy_install installed. Installation should be as easy as typing:
easy_install bbfreeze
This should download bbfreeze and it's dependencies modulegraph and altgraph and install them.
bb-freeze - command line tool
bbfreeze provides a command line utility called bb-freeze, which freezes all python scripts given on the command line into the directory dist, which then contains for each script an executable and all dependencies needed by those executables.
Example Usage:
$ cat hello-world.py
#! /usr/bin/env python
import sys
import email
print unicode("hello", "utf8"), unicode("world!", "ascii")
print "sys.path:", sys.path
print "__file__:", __file__
print "__name__:", __name__
print "locals():", locals()
print "sys.argv", sys.argv
print "sys.executable:", sys.executable
$ bb-freeze hello-world.py
*** applied
$ dist/hello-world
hello world!
...
$ dist/py
Python 2.5.1c1 (r251c1:54692, Apr 11 2007, 01:40:50)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(MyConsole)
>>> import email
$
bdist_bbfreeze - distutils command
bbfreeze provides a distutils command which works much like the 'bb-freeze' command line tool, but integrates nicely into distutils and setuptools. It collects all 'console_scripts' 'gui_scripts' entry-points, generates the wrapper scripts (like easy_install would do) and freezes these scripts.
After installing bbfreeze, every setup.py which used setuptools, has a new command 'bdist_bbfreeze'. To show the help message just run:
python setup.py bdist_bbfreeze --help
Usage examples:
# freeze all scripts into ./dist/-/ python setup.py bdist_bbfreeze
# same, but use tagging for "daily build" or "snapshot" releases python setup.py egg_info --tag-build=dev bdist_bbfreeze
bbfreeze - API
The preferred way to use bbfreeze is by writing short python scripts, which use bbfreeze's API. Let's start with a short example:
from bbfreeze import Freezer
f = Freezer("hello-world-1.0", includes=("_strptime",))
f.addScript("hello-world.py")
f.addScript("hello-version.py")
f() # starts the freezing process
bbfreeze.Freezer(distdir="dist", includes=(), excludes=()) instantiates a Freezer object. It will create the frozen executables and dependencies inside the distdir directory. includes is a list or tuple of modules to include, excludes is a list or tuple of modules to exclude. Note that the freezer will delete the directory distdir before freezing!
bbfreeze.Freezer objects have the following members:
* use_compression: flag whether to use compression inside the created zipfile (default True).
* include_py: flag whether to create the included python interpreter py (default True)
* addScript(path, gui_only=False): register a python script for freezing. path must be the path to a python script. The freezer will scan the file for dependencies and will create an executable with the same name in distdir. The gui_only flag only has a meaning on windows: If set, the executable created for this script will not open a console window.
Recipes
Recipes provide a way to control the freezing process. Have a look at bbfreeze/recipes.py if you need to implement your own. Note that the API might change.
Linux Notes
The glibc version on the system used for freezing will generally be the minimum glibc version required to run the binaries.
gtk, gdk, pango, glib shared libraries will not be copied by the freezing process. Those need a rather complicated runtime system and copying them would probably only lead to problems.
Product's homepage
Requirements:
· Python
Limitations:
· documentation is a bit sparse
What's New in This Release: [ read full changelog ]
· better test infrastructure
· update documentation
· remove bbfreeze.macholib
· fix build on ubuntu 11.10
· handle platform=='linux3' case in ensureRPath
· make py recipe work again.
· handle "pip -e" installed development eggs, that aren't even setuptools packages