Bootstraping 'frozen' python... anyone done this before?

Philip Swartzleonard starx at pacbell.net
Sun Feb 10 06:47:05 EST 2002


I've been wondering how to distribute an application program in python 
for a while now -- most of the disutils and installing and information 
seems to assume you're working with libraries. I was also wondering how 
to make a standalone version (for people who don't have all the right 
versions on hand and don't want to get them, or people who just don't 
have python), and leave the code in the open, and how to make it 
reasonably sized. I think i've got a solution that works for me now (and 
realizing it was sort of a 'oh, duh' experience). Just make a standalone 
out of a simple script with all of the libs you need and run the real 
program from there.

Another benefit of this is that it seperates all of the supporing crap 
(which totals at 11 megs, though i should try and get rid of all the TK 
stuff and it will be around 7), which only ever changes when i upgrade 
my development libraries, and the small, continully changing code that 
actually defines my program, which is now at about 370k including a few 
tile-textures.

Here's a copy of the bootstrapping loader-script i came up with, even 
with minimal runtime configuration abilities. (It's so minimal because i 
didn't want to import anything at all to do it, and i thought it should 
be exceedingly simplistic at the time :)

This works great with the Macmillian Installer module-thing, but you 
could probably swing it with py2exe too.

Ok, no more posting w/o more sleep for now =)

# Project Includes
import wxPython.wx
import PyCrust.crust
import OpenGL
import OpenGLContext.wxcontext
import Image
import random
import crements
# Whatever you need to have on hand in the finished program.
# (Could be other ways if you don't want to import them immediatly,
# but i load them all before doing anything anyway)

try:
    cfg_file = open("execframe.cfg")
    bootscript_name = cfg_file.readline()
    bootscript_name = bootscript_name.strip()
    cfg_file.close()
except IOError:
    print "*** No execframe.cfg, using default boot-script name ***"
    bootscript_name = "sproject.py"

print '*** Loading boot-script: ', bootscript_name, '***'
try:
    execfile( bootscript_name, {'__builtins__':__builtins__,
                                '__name__':'__main__'} )
except IOError:
    print '*** File error, boot-script not found ***'

print '*** Press Enter to Exit ***'
raw_input()

-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list