How to Make Python Script Executable

Updated February 21, 2017

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."

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.

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

print "Hello, world!"

can be saved as

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

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.

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.

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Wolfram Donat is an information technology professional and writer currently finishing a degree in computer systems engineering. He has had success writing for both on- and offline audiences, and moonlights as a professional copywriter as studies permit. He is currently shopping his first novel to agents and publishers, and is hard at work on his second.