August 14, 2011

Python to Windows executable

To convert my Python programs to Windows executables I use Py2exe and here goes some line about how to use it. So you installed it and wana convert your .py file to .exe. First you need a setup script like the following:

import sets
from distutils.core import setup
import py2exe
setup(windows=['yourprogram.py'])


The 'windows' key makes your program run without a console, if you wana run your program with an ugly looking console write 'console' instead. It is just a minimalistick script, if you wana add icon picture or other stuffs look documentation on web.

Next thing is after you saved your setup.py script is run the script. But don't use IDLE for it. Use command line. Like this: "c:\python\python.exe setup.py py2exe" As you can see the main things are define the program (python.exe) that you wana use for execute setup.py and add py2exe for run setup.py with py2exe option.

After a bunch of lines its over, and you will find two new directory, where your setup.py. These are build and dist. You dont need the build dir just the dist one. All the files in the dist directory that you need to use for run your program without an installed Python. So zip them for distribution.

If you use fonts in your program and after the conversation it gives you error messages its could be because of missing fonts. To solve this just copy the following files to your dist filder. "SDL_ttf.dll, font.pyd, libfreetype-6.dll"

Thats all...

No comments:

Post a Comment