PyInstaller bundles a Python application and all its dependencies into a single package.
—
PyInstaller's command-line interface provides comprehensive options for creating standalone executables from Python applications. The CLI handles everything from basic script bundling to complex multi-file applications with custom configurations.
The primary pyinstaller command analyzes Python scripts and creates standalone executables.
def run(pyi_args=None, pyi_config=None):
"""
Main entry point for running PyInstaller programmatically.
Args:
pyi_args (list, optional): Command-line arguments. If None, uses sys.argv[1:]
pyi_config (dict, optional): Configuration dictionary for multiple builds
Raises:
SystemExit: On invalid arguments or build failure
RecursionError: When recursion limit exceeded during analysis
KeyboardInterrupt: On user cancellation
"""Create a standalone executable that unpacks itself when run:
pyinstaller --onefile myscript.pyCreate a directory containing the executable and all dependencies:
pyinstaller --onedir myscript.pyCreate an application without console window (Windows/macOS):
pyinstaller --windowed myapp.pyInclude additional data files in the bundle:
# Single file
pyinstaller --add-data "config.ini:." myscript.py
# Directory (Unix)
pyinstaller --add-data "data/*:data" myscript.py
# Directory (Windows)
pyinstaller --add-data "data/*;data" myscript.pyInclude binary dependencies:
pyinstaller --add-binary "libs/mylib.so:libs" myscript.pyForce inclusion of modules not detected automatically:
pyinstaller --hidden-import scipy.integrate myscript.pyExclude modules to reduce bundle size:
pyinstaller --exclude-module matplotlib myscript.pySpecify output names and directories:
# Custom executable name
pyinstaller --name MyApplication myscript.py
# Custom output directory
pyinstaller --distpath /path/to/output myscript.py
# Custom working directory
pyinstaller --workpath /tmp/pyinstaller myscript.py
# Custom spec file location
pyinstaller --specpath /path/to/specs myscript.pyRemove output and working directories before building:
pyinstaller --clean myscript.pyCompress binaries using UPX:
# Enable UPX for all binaries
pyinstaller --upx-dir /usr/local/bin myscript.py
# Exclude specific files from UPX
pyinstaller --upx-exclude vcruntime140.dll myscript.pyRemove debug symbols from binaries:
pyinstaller --strip myscript.pySpecify additional hook directories:
pyinstaller --additional-hooks-dir /path/to/hooks myscript.pyAdd runtime hooks that execute at application startup:
pyinstaller --runtime-hook runtime_hook.py myscript.pyAdd directories to Python path during analysis:
pyinstaller --paths /extra/python/path myscript.py# Request administrator privileges
pyinstaller --uac-admin myscript.py
# Add version resource file
pyinstaller --version-file version.txt myscript.py
# Add custom icon
pyinstaller --icon app.ico myscript.py
# Add Windows manifest
pyinstaller --manifest manifest.xml myscript.py# Add application icon
pyinstaller --icon app.icns myscript.py
# Enable macOS app bundle creation
pyinstaller --windowed --osx-bundle-identifier com.example.app myscript.py
# Add entitlements file
pyinstaller --osx-entitlements-file entitlements.plist myscript.py# Increase verbosity
pyinstaller --log-level DEBUG myscript.py
# Quiet output
pyinstaller --log-level WARN myscript.py# Include debug information in executable
pyinstaller --debug all myscript.py
# Debug imports only
pyinstaller --debug imports myscript.pyCreate a .spec file without building:
pyinstaller --specpath . --name MyApp --onefile myscript.py --noconfirmThen edit the .spec file and build with:
pyinstaller MyApp.specpyinstaller \
--onefile \
--windowed \
--name "My Application" \
--icon app.ico \
--add-data "config/*:config" \
--hidden-import pkg_resources.py2_warn \
--clean \
main.pypyinstaller \
--onedir \
--console \
--debug all \
--clean \
main.pypyinstaller \
--onefile \
--strip \
--upx-dir /usr/bin \
--exclude-module matplotlib \
--exclude-module numpy \
main.pyPYINSTALLER_COMPILE_BOOTLOADER: Force bootloader compilationPYINSTALLER_BOOTLOADER_WAF_ARGS: Additional WAF arguments for bootloader compilationInstall with Tessl CLI
npx tessl i tessl/pypi-pyinstaller