Create a Single Standalone .exe From a Python Program

I have been working on a small windows command line tool that I wanted to distribute it as a single executable file on windows. I tried cx_freeze and py2exe. Both of these tools worked well, but I couldn’t find an easy way to compress make the whole program into a .exe file. py2exe and cx_freeze both create working programs, but there are always some dependent .zip archive or .dll’s somewhere that need to be distributed with it. Pyinstaller, I found, actually compresses everything into a single .exe. This makes a pretty big executable (my small command line utility created a 5MB .exe file), but it’s simple and it works.

To use pyinstaller:

  1. grab pyinstaller 1.5rc (1.4 doesn’t work with python 2.7). extract the zip file anywhere.

  2. change directories to the pyinstaller folder you just created.

  3. Before you create your first executable, you will have to run this once.

    python configure.py

  4. Now, pyinstall needs to scan through your program and create what they call a spec file.

    python makespec.py —onefile path\to\program\program.py

  5. Now, run this command to generate the executable.

    python build.py program\program.spec

Once the command has finished, the standalone executable will be available in the program\dist folder inside of pyinstaller. Instructions for how to do this for a linux executable on ubuntu linux can be found here: http://excid3.com/blog/2009/12/pyinstaller-a-simple-tutorial/. You can find more info on pyinstaller at their website: http://www.pyinstaller.org/.

from:http://www.surlyjake.com/blog/2011/03/28/create-a-single-standalone-exe-from-a-python-program/

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注