Creating a Python Executable File Using

Creating a Python Executable File Using

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)

## 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/ ") 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 = "" 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 setupimport py2exesetup(name = "%s", scripts = ["%s"],)""" % (package,fileName)fp.write(temp)fp.close()


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

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

See also - an AI reverse image search platform

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist