How to Create Executable Applications in Python (2024)

Used by NASA, ILM, Disney and hardware hackers, Python is a versatile programming language and an ideal choice for beginners. Whether you’re just creating a “Hello World” or a full-blown application, Python needs an interpreter and a bunch of supporting libraries to work. What if we could make a GUI application, all bundled inside of a single executable file?

How to Create Executable Applications in Python (1)

With auto-py-to-exe ,a project by Brent Vollebregt we can easily create our own executable Python applications. Underneath the GUI is PyInstaller, a terminal based application to create Python executables for Windows, Mac and Linux. Veteran Pythonistas will be familiar with how PyInstaller works, but with auto-py-to-exe any user can easily create a single Python executable for their system.

In this how to, we are going to create a GUI Python application using EasyGUI, and then use auto-py-to-exe to create a standalone application that will run on any Microsoft Windows system, including systems without Python installed. Linux and Mac users will need to use the underlying PyInstaller command line tool. A simple app can be created using a single line instruction. By adding more arguments we can include icons, packaged libraries etc.

For example here is the code to create a onefile application using app.py as the project code.

pyinstaller --onefile app.py

Where auto-py-to-exe differs is that we have an easier means to create an application using a GUI tool.

How to Install auto-py-to-exe

1. Open a Command Prompt by searching for CMD.

How to Create Executable Applications in Python (2)

2. Use the Python package manager pip to install auto-py-to-exe.

Stay on the Cutting Edge

Join the experts who read Tom's Hardware for the inside track on enthusiast PC tech news — and have for over 25 years. We'll send breaking news and in-depth reviews of CPUs, GPUs, AI, maker hardware and more straight to your inbox.

pip install auto-py-to-exe

Create a Test Script

Our example application is a simple GUI to launch one of three applications. We use the EasyGUI Python library as it abstracts the complexities of creating a GUI application. All we need to provide is the logic that drives the application.

1. Open a PowerShell by right clicking on the Windows icon and selecting PowerShell.

2. Install EasyGUI using pip.

pip install easygui

3. Open a text editor to write the Python test script. We chose to use Notepad++, but you are free to use your favorite editor.

4. Import two Python modules, easygui and os. Easygui creates the GUI application and OS enables the code to interact with the operating system.

import easyguiimport os

5. Create two variables, one for a message (msg) to the user while the other becomes the application title.

msg = "Load application..."title="Tom's Hardware Application Starter"

6. Create a list, choices, and inside store three values which are the application names. Lists are Python’s arrays. Objects that can store multiple items. Each item has a numerical index, starting from zero.

choices = ["Google Chrome","Slack","PuTTY"]

7. Create an object, reply, to ask the user a question. In this case we use a button box from EasyGUI, each button is an option from the choices list. The chosen application is stored in the reply object.

reply = easygui.buttonbox(msg, title, choices=choices)

8. Use a conditional statement to read the value stored in reply and compare it to three conditions. The first checks reply to see if it contains “Google Chrome” if so it will open the Google Chrome browser. The startfile function requires the use of a full file path to the application. We need to use double \\ in the path as Python uses \ to insert illegal characters into a string.

if reply == "Google Chrome": os.startfile("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe")

9. Use another conditional statement to check reply for slack.

elif reply == "Slack": os.startfile("C:\\Users\\lespo\\AppData\\Local\\slack\\slack.exe")

10. Add another conditional statement to load PuTTY. Note that for PuTTY we use the os.system function as PuTTY is a registered app with the Windows path.

elif reply == "PuTTY": os.system("putty")

11. Close the conditional test with an else condition to catch any other input.

else: print("Done")

12. Save the file as app.py to the Desktop. If you are using an image in the application ensure that the image is also on the Desktop.

Complete Example Code Listing

import easyguiimport osmsg = "Load application..."title="Tom's Hardware Application Starter"choices = ["Google Chrome","Slack","PuTTY"]reply = easygui.buttonbox(msg, title , choices=choices)if reply == "Google Chrome": os.startfile("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe")elif reply == "Slack": os.startfile("C:\\Users\\lespo\\AppData\\Local\\slack\\slack.exe")elif reply == "PuTTY": os.system("putty")else: print("Done")

Using auto-py-to-exe

1. Open a Command Prompt by searching for CMD.

How to Create Executable Applications in Python (3)

2. Run auto-py-to-exe from the prompt.

auto-py-to-exe

How to Create Executable Applications in Python (4)

3. Click on Browse and navigate to our example Python file.

How to Create Executable Applications in Python (5)

4. Set the application to use one file. This will condense the application and the supporting Python libraries into a single executable file.

How to Create Executable Applications in Python (6)

5. Set the application to be Console Based. By doing this we will see any errors outputted to the Command Prompt. Once we are confident that the app works correctly, we can set this to Window Based.

How to Create Executable Applications in Python (7)

6. Click on the Icon drop down and select an icon for your application. This is an optional step but it adds an extra level of quality to your application. Icons must be .ico files and we used a 64x64 pixel image as an icon.

How to Create Executable Applications in Python (8)

7. Click on Advanced and, under –name, enter the name of your application. We chose App Launcher.

How to Create Executable Applications in Python (9)

8. Scroll down and click on CONVERT .PY to .EXE to start the process. This will take a couple of minutes.

How to Create Executable Applications in Python (10)

9. Click on Open Output Folder to open the folder containing the application.

How to Create Executable Applications in Python (11)

10. Double click on the icon to run your application.

Python How Tos

  • How To Install Python on Windows 10 and 11
  • How to use For Loops in Python
  • How to Enumerate in Python
  • How to Create Executable Applications in Python
  • How To Remove Backgrounds From Images With Python
  • How to Create Web Apps with Python, HTML and Thonny
  • How To Use Raspberry Pi Camera Module 3 with Python Code
How to Create Executable Applications in Python (2024)
Top Articles
Alibaba Cloud: Reliable Secure Cloud Solutions to Empower Your Global Business
What Is a Theory? A Scientific Definition | AMNH
No Hard Feelings (2023) Tickets & Showtimes
Top 11 Best Bloxburg House Ideas in Roblox - NeuralGamer
Dee Dee Blanchard Crime Scene Photos
Buckaroo Blog
House Share: What we learned living with strangers
Unit 1 Lesson 5 Practice Problems Answer Key
978-0137606801
Bowie Tx Craigslist
Sony E 18-200mm F3.5-6.3 OSS LE Review
How To Cut Eelgrass Grounded
2 Corinthians 6 Nlt
Saatva Memory Foam Hybrid mattress review 2024
Gentle Dental Northpointe
What Is Vioc On Credit Card Statement
Dallas Craigslist Org Dallas
Marine Forecast Sandy Hook To Manasquan Inlet
Gas Buddy Prices Near Me Zip Code
Craigslist Pennsylvania Poconos
Sister Souljah Net Worth
Troy Gamefarm Prices
Wrights Camper & Auto Sales Llc
Is Henry Dicarlo Leaving Ktla
1636 Pokemon Fire Red U Squirrels Download
Things to do in Pearl City: Honolulu, HI Travel Guide by 10Best
Eegees Gift Card Balance
24 slang words teens and Gen Zers are using in 2020, and what they really mean
Edward Walk In Clinic Plainfield Il
M3Gan Showtimes Near Cinemark North Hills And Xd
Lichen - 1.17.0 - Gemsbok! Antler Windchimes! Shoji Screens!
Www Violationinfo Com Login New Orleans
Maybe Meant To Be Chapter 43
Etowah County Sheriff Dept
Caderno 2 Aulas Medicina - Matemática
Dadeclerk
Fapello.clm
Sabrina Scharf Net Worth
Cranston Sewer Tax
Sofia Franklyn Leaks
Pain Out Maxx Kratom
Leland Nc Craigslist
Gonzalo Lira Net Worth
Adams-Buggs Funeral Services Obituaries
Walmart Front Door Wreaths
Shannon Sharpe Pointing Gif
Frank 26 Forum
How Did Natalie Earnheart Lose Weight
Access One Ummc
Electronics coupons, offers & promotions | The Los Angeles Times
Guidance | GreenStar™ 3 2630 Display
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 6177

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.