How to Make Python Script Executable

Written by wolfram donat
  • Share
  • Tweet
  • Share
  • Email

One reason for Python's increased popularity as a high-level programming language is its portability. Scripts written on a Mac, for example, will run on a Windows machine and vice versa. As long as the destination machine has Python installed on it, the script will run without problems. Most Python scripts are saved as scripts; they are not self-contained, and they are normally executed by typing "python" in a command prompt. However, this method of running the scripts requires a Python installation. It is possible to make a Python script executable -- with no Python installation required -- by turning it into a "frozen binary."

Skill level:


  1. 1

    Download and install a frozen binary system. Three systems are commonly used. Py2exe (for Windows) is available at Py2app (a Mac version of Py2exe) is available at PyInstaller (for Windows, Mac and Linux) is available at

    To install py2exe, download the .ZIP file and unpack it. No installation is required.

    To install py2app, download the .TAR.GZ file from and unpack it. Open a terminal and navigate to the directory in which you unpacked the files. Type:

    python install

    and the program will install itself.

    To install PyInstaller, download the .ZIP file from the main page and unpack it. Open a terminal or command line and navigate to the unpacked contents directory. Type


    and the program will install and configure itself.

  2. 2

    Write your Python script that you wish to save as an executable. For example:

    print "Hello, world!"

    can be saved as

  3. 3

    Use Py2exe or Py2app to create an executable. Because Py2app is the Mac version of Py2exe, the sequences to use them are similar. Both require a script. In Py2exe:

    from distutils.core import set-up

    import py2exe


    will import the setup function from distutils, import the py2exe module, and then setup the console application

    In Py2app, you can use the Py2applet script to create the

    py2applet --make-setup

    This creates

  4. 4

    Run your set-up script:

    Python Py2exe

    This will create the hello.exe file, which is a self-contained executable.

    For Py2app, type

    python py2app -A

    This will create the file, which is a self-contained app file that can be run from the terminal.

  5. 5

    Create a spec file in PyInstaller by navigating to your script folder and typing

    python [--onefile]

    Build your project with:

    python specfile

    This creates a standalone .EXE file.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.