By Damien LEFEVRE: Friday 30 June 2006, 11:09
Standalone application with Py2exe
Here is what you have to do to "compile" your Python script into a standalone application with files, images...
- First of all you need to get the latest version of py2exe. Have a look at SourceForge
- Now create a new python file in your script folder you want to transform to exe. I named mine setup.py :)
- Edit it to put some informations. The following script is the one I used with my last application
from distutils.core import setup import py2exe
_prog = "script.py" _name = "app_name" _vers = "0.1" _desc = "app_name does that and that" _auth = "LEFEVRE Damien" _email = "feedback@lfdm.net" __url = "http://www.lfdm.net" _files = ["file1", "file2, "file3", "img1.png", "img2.png", "img3.png"]
setup( windows=[_prog], name = _name, version = _vers, description = _desc, author = _auth, author_email = _email, url = __url, data_files = _files)
- I'm using PIL to display image in the application. In my case if you run py2exe now the operation will succeed but the program will never on standalone application.
You need to import in your script the right image plugin for type of pictures you are using. I'm using PNG and BMP image, so I need to add in the application script:
import PngImagePlugin import BmpImagePlugin
- Your application should now be able to "compile". Open the command prompt Start > run > cmd and execute the commands below:
C:\>cd your_script_folder_location ...\>setup.py py2exe
- If success you get 2 folders, dist and build. Your standalone application in located in bist
- (optional) To get optimized bytecode, you need to call the setup.py like so:
...\>python -OO setup.py py2exe



Comments
No comment for the moment.
Add a comment
Les commentaires pour ce billet sont fermés.