Guide for packaging Python apps with PyInstaller for Windows and macOS
Guide for packaging Python applications into professional executable files (.exe, .app) using PyInstaller.
pip install pyinstaller
| Flag | Meaning |
| ----------------- | ----------------------------------------------------------- |
| --onefile | Bundle everything into a single file (good for small tools) |
| --onedir | Keep folder structure (good for large apps, faster startup) |
| --windowed | Hide console window (GUI apps) |
| --noconsole | Same as --windowed |
| --name "App" | Set output filename |
| --icon=icon.ico | Set icon (Windows: .ico, Mac: .icns) |
python -m PyInstaller --onefile --noconsole --name "MyApp" main.py
python -m PyInstaller --onefile --name "MyTool" main.py
--onefile. Use --onedir if avoiding this is priority..ico file.python -m PyInstaller --windowed --noconsole --name "MyApp" main.py
--onefile very well (slow startup). Recommend default (--onedir) or --windowed..app bundle, not a single file.When packaging with --onefile, assets are unpacked to a temp folder _MEIxxxx. Code is needed to find the correct path:
import sys
import os
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
# Usage
icon_path = resource_path("icon.png")
Use --add-data flag:
--add-data "src;dest"--add-data "src:dest"Example:
# Windows
pyinstaller --onefile --add-data "config.json;." main.py
Always optimize requirements.txt before building to reduce exe size.
pip freeze > requirements.txt (Captures all system junk libraries)
List only actually used libraries:
PyQt6>=6.4.0
pandas
openpyxl
pillow
PyInstaller is NOT a Cross-Compiler.
.exe file -> Must build on Windows..app file -> Must build on macOS.Solutions:
pip install -r requirements.txt firstpython main.pyresource_path)dist/ directoryWhen activating this skill, print: "🎯 [SKILL ACTIVATED] python-packaging v1.0.0" "📋 Parameters:" " - Target: [script.py]" " - Mode: [onefile|onedir]" " - OS: [Windows|macOS]" " - Assets: [list_of_included_assets]"
Before running the build command (long process): "I'm about to package [Target] using PyInstaller with options: [Options]. This may take a few minutes. Proceed?"
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer