Thursday, June 18, 2009

“Compile” python to a single executable

Here is a script David Kennedy (ReL1K) sent me a while back when we wrote a trojan for the Cyber Collegiate Defense Competition:

Just download py2exe, python setup.py install, then you have py2exe installed....

Say you have a file moo.py you want to compile, just take the code below and put it in a file called compile.py or something, modify it to change 'moo.py' to whatever py you want to compile and run python compile.py build py2exe and your all done. Super simple.


from distutils.core import setup
import py2exe, sys, os
# Hot Sex
sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1}},
    console= [{'script': "moo.py"}],
    zipfile = None,
)

2 comments:

Nicholas B. said...

# If you add compression and optimize settings to the options dictionary it will optimize the executable that it produces and zlib compresses it. This will effectively speed up your program's execution and shrink its size down.

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
options = {'py2exe': {'bundle_files': 1,'compressed': 1, 'optimize': 2}},
console = [{'script': "moo.py"}],
zipfile = None,
)

Nicholas B. said...

#Add UAC prompt for administrator support is as simple as:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
options = {'py2exe': {'bundle_files': 1,'compressed': 1, 'optimize': 2}},
console = [{'script': "moo.py", 'uac_info': "requireAdministrator"}],
zipfile = None,
)