Compile .py file to .exe for Windows

Py2exe is a freeware utility which will build an .exe from .py file(s)

To build an .exe under windows create a file for example setup.py which includes some py2exe attributes. The following example creates a HelloWorld.exe which prints the 'Hello World' greeting 25 times.

for i in range(25):
	print "Hello World " + str(i+1)

For this example I use setup.py which is as follows:

from distutils.core import setup
import py2exe
 
setup(console=['hello.py'])

To build the exe run the setup with the option py2exe.

setup.py py2exe

This will create a folder called dist (default), where you will find all files releated to executing hello.exe including any necessary DLL files. At this point you may using a Win installer like NullSoft installer NSIS to build an installer for the hello.exe.

Py2exe supports most modules, please refer to their home page for more options and examples.


* Back to Python

py2exe.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0