Python PyInstaller Module
PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules.
Installation
pip install pyinstaller
Basic Usage
To bundle a script, run PyInstaller against your main script:
pyinstaller myscript.py
This creates a dist folder containing the executable.
Common Options
One-File Mode
Create a single executable file instead of a directory.
pyinstaller --onefile myscript.py
Windowed Mode (No Console)
For GUI applications (like Tkinter or PyQt), use -w or --noconsole to prevent the terminal window from appearing.
pyinstaller --noconsole myscript.py
Adding Data Files
If your script relies on external data files (images, config), use --add-data.
- Windows:
--add-data "src;dest" - Linux/Mac:
--add-data "src:dest"
pyinstaller --add-data "image.png;." myscript.py
The Spec File
When you run PyInstaller, it generates a .spec file. You can modify this file to customize the build process (e.g., adding hidden imports, changing the icon) and then run PyInstaller against the spec file.
pyinstaller myscript.spec