This project demonstrates how to convert a Python file into a full standalone .exe application using PyInstaller.
It’s a crucial step for Python developers who want to share their projects with non-technical users who may not have Python installed on their systems.
The process involves packaging your code, dependencies, and resources into a single executable file that can run on any Windows system.
This guide also includes fixes for common errors, the use of a custom icon, and error handling setup inside the Python code to ensure a smooth build.
Convert any .py file into .exe format
Add custom application icons (.ico files)
Build lightweight single-file executables (--onefile)
Remove console window for GUI apps (--windowed)
Automatically log errors into a file
Works on all Windows versions
Python 3
PyInstaller
pip install pyinstaller
Open the folder where your Python file is saved.
In the address bar, type:
cmd
and press Enter.
pyinstaller --onefile Your_File_Name.py
If your app gives an error, add the following code at the top of your script:
import sys, os
if getattr(sys, 'frozen', False):
sys.stdout = open(os.devnull, 'w')
sys.stderr = open("error.log", 'w')
Then rebuild using:
pyinstaller --onefile --windowed Your_File_Name.py
To include your custom .ico icon:
pyinstaller --onefile --windowed --icon=icon.ico Your_File_Name.py
Once your .exe file is generated inside the dist folder, compress it into a .zip file for easy sharing.
Let’s chat and discover how our all-in-one digital solutions can help you attract, engage, and convert more customers.
WhatsApp us