Overview
ThePyInstallerBuilder class provides a high-level interface for creating standalone executables using PyInstaller. It handles resource bundling, icon conversion, and PyInstaller configuration automatically.
Features
- Single-file executables using
--onefile - No console window with
--noconsole - Automatic resource bundling from multiple packages
- Platform-specific icon conversion (PNG → ICO/ICNS/PNG)
- Multi-package resource discovery from entire dependency chain
- Clean builds with
--clean
Quick Start
1. Create a Builder Class
Create a file inpyrig/rig/builders/app_builder.py:
2. Add an Icon
Place anicon.png file in your resources directory:
3. Build
Run the build command:dist/myapp-Linux (or -Windows.exe / -Darwin depending on platform).
Resource Bundling
Automatic Discovery
PyInstallerBuilder automatically discovers and bundles resources from:- Default resources - All
resourcesmodules from packages depending on pyrig - Additional resources - Packages specified in
additional_resource_packages()
How It Works
--add-data option and accessible at runtime via importlib.resources or pyrig.src.resource.
Accessing Bundled Resources
At runtime, access resources using standard Python APIs:Icon Conversion
Platform-Specific Icons
The builder automatically converts your PNG icon to the appropriate format:- Windows: PNG → ICO
- macOS: PNG → ICNS
- Linux: PNG (no conversion)
Icon Requirements
- Format: PNG
- Location:
{package}/resources/icon.png - Size: 256x256 recommended (for best compatibility)
- For ICNS: Multiple sizes (16, 32, 128, 256, 512) provide better results
Custom Icon Location
Overrideapp_icon_png_path() to use a custom location:
PyInstaller Configuration
Default Options
The builder uses these PyInstaller options by default:--onefile- Create a single executable file--noconsole- No console window (GUI app)--clean- Clean PyInstaller cache before building--noconfirm- Replace output directory without confirmation--name <app_name>- Executable name frompyproject.toml--icon <icon>- Platform-specific icon--add-data <resources>- All discovered resource files
Customizing Options
Overridepyinstaller_options() for full control:
Advanced Usage
Multi-Package Applications
For applications built from multiple packages:Custom Data Files
Add additional data files usingadd_datas():
Build Directory Customization
The builder creates several temporary directories during the build:- workpath - PyInstaller intermediate files
- specpath - Generated
.specfile - distpath - Final executable output (moved to
dist/)
Complete Example
Here’s a complete example with all features:dist/myapp-Linux (or Windows/Darwin variant)
Troubleshooting
Missing Resources
If resources aren’t accessible at runtime:- Verify the package is listed in
additional_resource_packages() - Check that the package has an
__init__.pyfile - Ensure you’re using
importlib.resourcesorpyrig.src.resourceto access resources
Icon Not Appearing
- Verify
icon.pngexists in resources directory - Check PNG format (256x256 recommended)
- For macOS, ensure PNG has proper dimensions for ICNS conversion
Build Fails
- Check PyInstaller is installed:
uv add --dev pyinstaller - Verify PIL/Pillow is available:
uv add --dev pillow - Run with verbose output: override
pyinstaller_options()and add--log-level DEBUG
API Reference
PyInstallerBuilder Methods
Return packages containing additional resources to bundle. Must be implemented by subclasses.Returns: Iterable[ModuleType] - Resource packages to bundle
Get resource packages from all pyrig-dependent packages. Automatically discovers
resources modules.Returns: Generator[ModuleType, None, None] - Auto-discovered resource packagesGet all resource packages (default + additional).Returns: Generator[ModuleType, None, None] - All resource packages
Build the
--add-data arguments for PyInstaller.Returns: list[tuple[str, str]] - List of (source, destination) tuplesBuild the complete PyInstaller command-line options.Args:
temp_artifacts_dir(Path): Temporary directory for the executable
Get the path to the application icon PNG. Override for custom icon location.Returns: Path - Path to icon.png
Get the platform-appropriate icon path (converts PNG to ICO/ICNS/PNG).Args:
temp_dir(Path): Temporary directory for converted icon
Convert the application icon PNG to another format.Args:
file_format(str): Target format (“ico”, “icns”, or “png”)temp_dir_path(Path): Directory for converted icon
Next Steps
Custom Builders
Create your own custom builders
Builders Overview
Learn more about the builder system