How to Make a Python Program, Script, or File (.py) Into a Standalone Executable Program/File (.exe)

by dwmitch84 in Circuits > Computers

514 Views, 4 Favorites, 0 Comments

How to Make a Python Program, Script, or File (.py) Into a Standalone Executable Program/File (.exe)

auto .py to .exe logo resized.jpg

These are some instructions I made on how to turn a Python script (.py) I made (see Custom_Python_Clock_-_Date_and_Time) into a single executable file (.exe). With this you can turn a Python script into a program that can be ran on any Windows computer (and apparently Mac OS) without the need to install any dependencies to run it.
One final thing that separates this and the Custom_Python_Clock_-_Date_and_Time projects from other similar projects is the fact that it was all created and done using programs off of a thumbdrive. This was done in part to show that you can make things from almost anywhere, even without having administrator privileges on the computer!

This whole project can also be found in my Github repository and is pretty much just a copy of that.

Supplies

Programs Used

Portable Python 3: Written in the Python language.

Portable Notepad++: Used to write, edit, and test the program.

Portable Git for Windows: Used to install any dependencies needed.

auto-py-to-exe: Used to turn the program its components into a single executable file that can be opened and ran on any Windows comptuer, without the need to install dependencies.

Files

Clock_white_sitting.py: Code file.

futurama_audience_500x287.png: Picture used as background.

futurama_audience_500x287_PZh_icon.ico: Icon file.

Install Auto-py-to-exe

step 1.jpg


Open your terminal and install auto-py-to-exe by running:

 pip install auto-py-to-exe


Run Auto-py-to-exe

step 2.jpg

Execute the following in the terminal:

auto-py-to-exe

Click "Browse" on "Script Location" and Select Your Python (.py) File

step 3.jpg

Under "Onefile" Select "One File", Then Under "Console Window" Click "Window Based (hide the Console)"

step 4 and 5.jpg

OPTIONAL: If You Have an Icon File (.ico) You'd Like to Use

step 6.jpg

Under "Icon" click "Browse" and select your icon file (.ico).

Special note, with a simple internet search you can find places to convert a picture into a .ico file for you to use. The link for this .ico file I used is at the beginning of this tutorial.

If There Is More to Your Program Than Just the Python File (.py)...

step 7.jpg

Under "Additional Files" click "Add Files" and select the files that are part of your program. In this instance it's the picture we're using for the background.

To Name Your Executable Program/file (.exe)

step 8.jpg

Under "Advanced"

> "General Options"

> "--name", then type in your desired name.

To Choose Where Your Executable Program/file (.exe) Is Made

step 9.jpg

Under "Settinngs"

> "auto-py-to-exe Specific Operations"

> "Output Directory"

> click "Browse" and select your desired location

Convert

step 10.jpg

At the very bottom of the window click "CONVERT .PY TO .EXE"

Open & Test

step 11.jpg

Finally, click "OPEN OUTPUT FOLDER" and test your new .exe file.

If your .exe file doesn't work, then click "CLEAR OUTPUT", double check your code and that you've selected everything required for it, and try again.

The .exe file will run on any Windows machine WITHOUT the need for you to install Python or any other dependencies on the other machines. I haven't tried it yet, but apparently you can also use the "auto-py-to-exe" program to make programs to run on Mac OS as well.