How do I make an executable from a Python script? Leave a comment

See cx_Freeze for a distutils extension that allows you to create console and GUI executables from Python code. py2exe, the most popular extension for building Python 2.x-based executables, does not yet support Python 3 but a version that does is in development.

Using cx_Freeze

cx_Freeze creates standalone executables from Python scripts, with the same performance, is cross-platform and should work on any platform that Python itself works on.

There are three different ways to use cx_Freeze:

  1. Use the included cxfreeze script.
  2. Create a distutils setup script. This is useful if you need extra options when freezing your program, because you can save them in the script. Run cxfreeze-quickstart to generate a simple setup script.
  3. Work directly with the classes and modules used internally by cx_Freeze. This should be reserved for complicated scripts or extending or embedding.

cx_Freeze normally produces a folder containing an executable file for your program, along with the shared libraries (DLLs or .so files) needed to run it. You can make a simple Windows installer using a setup script with the bdist_msi option, or a Mac disk image with bdist_dmg. For a more advanced Windows installer, use a separate tool like Inno Setup to package the files cx_Freeze collects.

Python modules for your executables are stored in a zip file. Packages are stored in the file system by default but can also be included in the zip file.

py2exe

py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.

Development is hosted on GitHub. You can find the mailing listsvn, and downloads for Python 2 there. Downloads for Python 3 are on PyPI.

py2exe was originally developed by Thomas Heller who still makes contributions. Jimmy Retzlaff, Mark Hammond, and Alberto Sottile have also made contributions. Code contributions are always welcome from the community and many people provide invaluable help on the mailing list and the Wiki.

py2exe is used by BitTorrentSpamBayes, and thousands more – py2exe averages over 5,000 downloads per month.

In an effort to limit Wiki spam, this front page is not editable. Feel free to edit other pages with content relevant to py2exe. You will need an account to edit (but not to read) and your account information will be used only for the purposes of administering this Wiki.

The old py2exe web site is still available until that information has found its way into this wiki.

Leave a Reply

%d bloggers like this: