Install PyInstaller
First, you need to install PyInstaller
pip install pyinstaller
Create an .exe file
Go to the folder with your Python files and run the command
pyinstaller --onefile --windowed filename.py
–onefile → Merge everything into a single .exe file
–windowed → Hide the Console (suitable for GUI Apps)
If it is a Console program, just use –onefile
Example:
Where is the .exe file?
After running the command, the .exe file will be in the dist/ folder
If you want to put an icon (.ico) on the .exe file created with PyInstaller, add –icon to the command like this:
pyinstaller --onefile --windowed --icon=youricon.ico myapp.py
More details
–icon=youricon.ico → Set icon for .exe file
The icon file must be .ico only (if it is .png or .jpg, it must be converted first)
youricon.ico must be in the same folder as myapp.py or include the full path
To create an installer file (Installer)
To create an .exe installer file (Setup.exe), you can use Inno Setup
Download Inno Setup Compiler → https://jrsoftware.org/isinfo.php
Use the script to create an .exe installer file for your program
Additional questions
Is your program a GUI (e.g. Tkinter, PyQt, Kivy) or a Console App?
Do you want to create a Setup.exe installer file or just .exe?
Do you want to add an icon (.ico) to the .exe file?
Tell me, I’ll help you!