bbfreeze - create standalone executables from python scripts
bbfreeze creates standalone 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.
- NEW 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)
bbfreeze works on windows and UNIX-like operating systems. It
currently does not work on OS X. bbfreeze has been tested with python
2.4 and 2.5. bbfreeze will not work with python versions prior to 2.3
as it uses the zipimport feature introduced with python 2.3.
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.
- bbfreeze does not work on OS X
- documentation
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 <function recipe_email at 0xb7ba702c>
$ 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
$
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 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.
- some egg packages have the site-packages directory as their
location, which resulted in the whole site-packages directory being
copied as some egg file.
- fix issue with wxPython
- add recipe for mercurial
- handle development eggs ("python setup.py develop") by running
setup.py bdist_egg
- handle easy install entry scripts
- add recipe for kinterbasdb (thanks to Werner F. Bruhin)
- fix LD_RUN_PATH issue, when --enable--new-dtags is the default for
linking (e.g. on gentoo). (thanks to Collin Day)
- workaround for virtualenv
- show execution time in py
- recipes for pythoncom/pywintypes have been added
- make sys.getfilesystemencoding() work like in non-frozen versions
- automatic pathname rewriting
- make stdin, stdout and stderr unbuffered in frozen programs
- fix issues with c modules with suffix 'module.so',
e.g. zlibmodule.so, timemodule.so, ... (fedora core 7 uses that
naming scheme; thanks to Neil Becker for reporting)
The frozen executable did bail out with zipimport.ZipImportError:
can't decompress data; zlib not available".
- compile .py files from eggs when there is no accompanying .pyc file
- skip egg/zip files in find_all_packages (makes some recipes work)
- support for egg files: bbfreeze scans zipped egg files and now
includes whole egg files/directories in the distribution. Programs
using setuptools' pkg_resources module will now work (thanks to
Eirik Svendsen for testing this).
- fix bug in setup script, now the patched modulegraph is really used
- better recipe handling
- support relative imports (backported from modulefinder, bbfreeze now
ships with its' own patched copy of modulegraph).
- fix xml/_xmlplus issues
- add recipe for cElementTree
- include tcl/tk runtime files (really makes Tkinter work)
- exclude gtk, pango and friends (i.e. they must be installed on
the target system)
- make py executable work when readline is not installed
- fix dll search path issue (makes Tkinter work)
- dependency on libpython.so should now always be recognized
- support for namespace packages
- basic support for zipfiles/eggs (bbfreeze will scan zipfiles/eggs
for dependencies and will implement a dummy pkg_resources.require in
frozen executables). Note that the remaining pkg_resources
functionality just isn't available.
- documentation updates
- better binary dependency cache handling
- fix recipe for time module on windows
- use pefile module on windows for binary dependency tracking
- add gui_only flag to addScript method (which builds GUI programs
on windows, i.e. without console)
- strip shared libraries on non windows platforms
- add showxref method
- working recipe for py.magic.greenlet
bbfreeze contains a modified copy of modulegraph, which is distributed
under the MIT license and is copyrighted by Bop Ippolito.
The remaining part is distributed under the zlib/libpng license:
Copyright (c) 2007 brainbot technologies AG
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
- The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
- Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
- This notice may not be removed or altered from any source
distribution.