Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Python
Expertise: Intermediate
Apr 17, 2004

Creating a Python Executable File Using makeExe.py

This file creates an executable file from a Python file specified by the user and writes the new executable to disk.

- Simple Python script to automate the creation
  of Python executables using py2exe.

(c) 2004 Premshree Pillai (24/01/04) http://www.qiksearch.com/

## Run this file from Python root dir

import sys
import re

def getFileName(): global fileName fileName = raw_input("Enter file name (rel or abs path, eg., python/file.py): ") try: fp = open(fileName) fp.close() except IOError: print "File does not exist!" getFileName()


package = re.split(":",fileName) package = re.split("/",package[len(package) - 1]) package = re.split(".py",package[len(package) - 1]) package = package[0]

def getSetupName(): global setupName setupName = raw_input( "Enter name of setup file (or for default): ") if(setupName == ''): setupName = "setup.py" try: fp = open(setupName) fp.close() flag = raw_input( "Setup file exists! Rewrite (0=no; else )? ") if(flag == "1"): getSetupName() except IOError: setupName = setupName


fp = open(setupName,"w") temp = """from distutils.core import setup import py2exe setup(name = "%s", scripts = ["%s"], )""" % (package,fileName) fp.write(temp) fp.close()

sys.argv.append("py2exe") execfile(setupName)

fp = open(setupName,"w") temp = "" fp.write(temp) fp.close()

print "\n", "Executable created!" print "Press to exit..." if(raw_input()):exit

Premshree Pillai
Thanks for your registration, follow us on our social networks to keep up-to-date