Create a standalone executable of a Python app
Alternatives
Most popular options:
Other alternatives:
- py2exe - Based on
pyinstaller
. For Windows. - py2app - Based on
pyinstaller
. For MacOS X. - PyOxidizer
Using pyinstaller
It's pretty straight forward:
1. Create an entry-point script that calls your main function.
2. Install PyInstaller.
3. Run PyInstaller on your entry-point.
4. Test your new executable.
5. Ship your resulting dist/
folder to users.
Install
To install pyinstaller
on your pc run (more details can be found here: https://www.pyinstaller.org/):
For a single file program
If your program is a single script use cmd
to go to your program directory and to turn it into a exe folder run
For a package
Create an entrypoint outside your package folder that imports and runs your program. This will be the entry point. Call pyinstaller on the entrypoint script as above.
Options
Change the name of your executable:
Package your entire application into a single executable file:
Insert additional data or binary files into your build:
Exclude some modules from being included with your executable:
Avoid automatically opening a console window for stdout logging:
What I usually run:
This makes it a single exe (without the folders with all dependables) but is slightly slower, minimizes the console window sine I have a GUI, and gives it a snazzy icon that I had saved (you have to copy over the icon, or have an exception incase it isn't found)