or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli-interface.mdcli-utilities.mdhook-development.mdindex.mdplatform-features.mdspec-file-classes.md
tile.json

tessl/pypi-pyinstaller

PyInstaller bundles a Python application and all its dependencies into a single package.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyinstaller@6.15.x

To install, run

npx @tessl/cli install tessl/pypi-pyinstaller@6.15.0

index.mddocs/

PyInstaller

PyInstaller is a mature Python application bundling tool that converts Python scripts and their dependencies into standalone executable packages. It analyzes Python code to discover all required modules and libraries, then collects copies of those files along with the Python interpreter into a single folder or executable file.

Package Information

  • Package Name: pyinstaller
  • Language: Python
  • Installation: pip install pyinstaller
  • Documentation: https://pyinstaller.org/

Core Imports

import PyInstaller

For programmatic usage:

from PyInstaller import run
from PyInstaller.building.build_main import Analysis
from PyInstaller.building.api import PYZ, EXE, COLLECT

For hook development:

from PyInstaller.utils.hooks import collect_submodules, collect_data_files

Basic Usage

Command Line Interface

# Create a standalone executable from a Python script
pyinstaller myscript.py

# Create a one-file executable
pyinstaller --onefile myscript.py

# Create a windowed application (no console)
pyinstaller --windowed myapp.py

# Add additional data files
pyinstaller --add-data "data/*:data" myscript.py

# Exclude modules to reduce size
pyinstaller --exclude-module matplotlib myscript.py

Programmatic Usage

from PyInstaller import run

# Run PyInstaller programmatically
run(['myscript.py', '--onefile', '--name=MyApp'])

Spec File Approach

# myapp.spec
from PyInstaller.building.build_main import Analysis
from PyInstaller.building.api import PYZ, EXE

a = Analysis(
    ['myapp.py'],
    pathex=[],
    binaries=[],
    datas=[('data/', 'data/')],
    hiddenimports=['hidden_module'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=None,
    noarchive=False
)

pyz = PYZ(a.pure, a.zipped_data, cipher=None)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='MyApp',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True
)

Architecture

PyInstaller uses a multi-stage build process:

  1. Analysis Phase: Discovers all dependencies through import analysis and hook execution
  2. Collection Phase: Gathers all required files (Python modules, extensions, data files)
  3. Packaging Phase: Creates archives and bundles files with bootloader
  4. Executable Generation: Produces final standalone executable or directory

The bootloader is a small C program that extracts and executes the bundled Python application at runtime, providing cross-platform compatibility without requiring Python installation on target systems.

Capabilities

CLI Interface

Command-line interface for creating standalone executables from Python applications with extensive configuration options for output format, optimization, and bundling behavior.

def run(pyi_args=None, pyi_config=None):
    """
    Main entry point for running PyInstaller programmatically.
    
    Args:
        pyi_args (list): Command-line arguments (defaults to sys.argv[1:])
        pyi_config (dict): Configuration dictionary for multiple builds
    """

CLI Interface

Spec File Building Classes

Core classes used in .spec files to define the build process, including dependency analysis, archive creation, and executable generation.

class Analysis:
    """Performs dependency analysis of Python scripts."""
    def __init__(self, scripts, pathex=[], binaries=[], datas=[], 
                 hiddenimports=[], hookspath=[], runtime_hooks=[], 
                 excludes=[], **kwargs): ...

class PYZ:
    """Creates zlib-compressed archive of compiled Python modules."""
    def __init__(self, *tocs, name=None): ...

class EXE:
    """Creates final executable from PKG and bootloader."""
    def __init__(self, *args, name='', console=True, debug=False, **kwargs): ...

class COLLECT:
    """Collects files into directory for onedir distribution."""
    def __init__(self, *args, name='', strip_binaries=False, **kwargs): ...

Spec File Classes

Hook Development Utilities

Functions for writing PyInstaller hooks to handle special cases in dependency collection, including module discovery, data file collection, and metadata handling.

def collect_submodules(package, filter=None, on_error="warn once"):
    """Recursively collect all submodules of a package."""

def collect_data_files(package, include_py_files=False, subdir=None, 
                      excludes=None, includes=None):
    """Collect data files from package installation."""

def collect_all(package_name, include_py_files=True, **kwargs):
    """Collect all components for a package."""

def can_import_module(module_name):
    """Test if module can be imported."""

Hook Development

CLI Utilities

Command-line tools for archive inspection, dependency analysis, version handling, and spec file generation.

# Console scripts available as commands:
# pyi-archive_viewer - Interactive archive viewer
# pyi-bindepend - Binary dependency analysis  
# pyi-grab_version - Windows version extraction
# pyi-makespec - Spec file generation
# pyi-set_version - Windows version setting

CLI Utilities

Platform-Specific Features

Windows and macOS specific functionality including icon handling, version resources, manifest embedding, code signing, and app bundle creation.

# Windows utilities (PyInstaller.utils.win32)
# - icon: Icon file handling
# - versioninfo: Version resource utilities
# - winmanifest: Manifest handling

# macOS utilities (PyInstaller.building.osx)
class BUNDLE:
    """Creates macOS application bundle (.app)."""
    def __init__(self, *args, name='', icon=None, bundle_identifier=None, **kwargs): ...

Platform Features

Constants and Configuration

# Version and path constants
__version__: str  # PyInstaller version
HOMEPATH: str     # PyInstaller home directory  
PLATFORM: str     # Platform identifier
DEFAULT_DISTPATH: str   # Default output directory (./dist)
DEFAULT_SPECPATH: str   # Default spec file directory (.)
DEFAULT_WORKPATH: str   # Default working directory (./build)

Exception Classes

class ExecCommandFailed(SystemExit):
    """Command execution failure."""

class HookError(Exception):
    """Base class for hook-related errors."""

class PythonLibraryNotFoundError(IOError):
    """Python shared library not found."""

class RemovedCipherFeatureError(SystemExit):
    """Deprecated cipher feature usage."""