bembry.org
Home / Technology / Python / Notes

Lesson 18 Notes: Sharing Your Python Apps with py2exe

  • What we need here …
    • Since python programs are interpreted (as opposed to being compiled) they will not run without the Python interpreter.
    • In order to share programs with folks who don't have Python installed, we have two choices:
      1. Get them to install Python
      2. Package the needed parts of Python with our program
  • py2exe
    • py2exe is a program that will package the needed portions of Python along with your script and make it an executable file.
    • py2exe is a separate module that must be downloaded and installed.
    • Download py2exe from http://starship.python.net/crew/theller/py2exe/
  • Using py2exe
    1. Download and install py2exe
    2. Write a setup script
    3. Run the setup script:
      setup.py py2exe
    4. If the script has a GUI, use the -w switch
      setup.py py2exe -w
  • A Sample Setup Script

      from distutils.core import setup
      import py2exe
      setup(name= "My Wonderful Program", version = "0.1", author = "Me", scripts=["myfile.py"])
    • Staying Alive

      • When an executable is run, it will exit as soon as it is finished. This may mean that the user never sees your program.
      • Before converting a GUI program, be sure to put the line root.mainloop() at the end of the program.
      • If a command line program exits unexpectedly, try adding the line exit = raw_input("Press [Enter] to exit") at the very end
    • For a more complete reference, see http://starship.python.net/crew/theller/py2exe/
Restricted access