Profile

Click to view full profile
Hi, I'm Veerapat Sriarunrungrueang, an expert in technology field, especially full stack web development and performance testing.This is my coding diary. I usually develop and keep code snippets or some tricks, and update to this diary when I have time. Nowadays, I've been giving counsel to many well-known firms in Thailand.
view more...

Thursday, October 6, 2011

Compile Python apps to .exe with py2exe

Normally, to run Python applications, we need to have a Python Interpreter. However, it's not always end in this way. If you are using Windows-based Operating Systems, you can compile your Python program to an executable file, and let other Windows-based users to use it without any of Python interpreter installation. You can download the py2exe from http://www.py2exe.org/ according to your Python version.

Examples:    A console application
print 'Hello World!'
 To compile console applications, create a setup.py file and then write the following code:  
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
Then, terminal access is required for compiling process. Write it as the following code:
python setup.py py2exe
Next, py2exe will try to generate the executable file for running that Python program on Windows.   A GUI application
from Tkinter import *
app = Tk()
app.mainloop()
 GUI applications need to modify console application setup code a bit as the following commands:
from distutils.core import setup
import py2exe
setup(windows=['ui.py'])
Then, use the same command that I already mentioned above. In addition, py2exe tutorial can be looked for more information at: http://www.py2exe.org/index.cgi/Tutorial

No comments:

Post a Comment