Thursday, August 13, 2009

py2exe functions

For those who don't want to figure out how to use py2exe use the following functions:


def main_is_frozen():
'''main_is_frozen() returns True when running the exe, and False when running from a script. '''
import sys, imp
return (hasattr(sys, "frozen") or # new py2exe
hasattr(sys, "importers") # old py2exe
or imp.is_frozen("__main__")) # tools/freeze

def create_exe():
'''If not an exe then create a single file exe from current script file'''
if main_is_frozen() == False:
from distutils.core import setup
import py2exe, sys

sys.argv = [sys.argv[0], 'py2exe']

setup(
console=[sys.argv[0]],
zipfile = None,
options = {
'py2exe':{
'bundle_files': 1,
'optimize' : 2,
'compressed' : True
}
}
)


No comments: