ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: makeExe.py
Submitter: Premshree Pillai (other recipes)
Last Updated: 2004/02/11
Version no: 1.1
Category: Programs

 

Not Rated yet


Description:

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

Source: Text Source

"""
makeExe.py
- 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()

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 <enter> for default): ")
	if(setupName == ''):
		setupName = "setup.py"
	try:
		fp = open(setupName)
		fp.close()
		flag = raw_input("Setup file exists! Rewrite (0=no; else <enter>)? ")
		if(flag == "1"):
			getSetupName()
	except IOError:
		setupName = setupName

getSetupName()

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 <enter> to exit..."
if(raw_input()):
	exit

Discussion:

To create Windows executables from Python scripts, we could make use of py2exe (available from http://starship.python.net/crew/theller/py2exe/). However this process is a little time-consuming. This Python script (makeExe.py) is an attempt to simplify this process.



Add comment

No comments.



Highest rated recipes:

1. A simple XML-RPC server

2. Web service accessible ...

3. a friendly mkdir()

4. SOLVING THE METACLASS ...

5. Povray for python

6. Changing return value ...

7. Implementation of sets ...

8. bag collection class

9. deque collection class

10. Floating Point Simulator




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.