CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-cx-freeze

Create standalone executables from Python scripts

Pending
Overview
Eval results
Files

executable-config.mddocs/

Executable Configuration

The Executable class defines the configuration for creating standalone executables from Python scripts. It supports extensive customization including base executable types, icons, metadata, and platform-specific options.

Capabilities

Executable Creation

Creates an executable configuration with comprehensive options for customizing the generated executable's behavior, appearance, and metadata.

class Executable:
    def __init__(
        self,
        script: str | Path,
        init_script: str | Path | None = None,
        base: str | Path | None = None,
        target_name: str | None = None,
        icon: str | Path | None = None,
        shortcut_name: str | None = None,
        shortcut_dir: str | Path | None = None,
        copyright: str | None = None,
        trademarks: str | None = None,
        manifest: str | Path | None = None,
        uac_admin: bool = False,
        uac_uiaccess: bool = False,
    ):
        """
        Create an executable configuration.

        Parameters:
        - script: Path to the main Python script to freeze
        - init_script: Initialization script executed before main script
        - base: Base executable type ("console", "gui", "service") or custom path
        - target_name: Name of the generated executable (without extension)
        - icon: Path to icon file (auto-detects .ico/.icns/.png/.svg extension)
        - shortcut_name: Name for MSI package shortcuts (Windows only)
        - shortcut_dir: Directory for MSI shortcuts (Windows only)
        - copyright: Copyright string for version resource (Windows only)
        - trademarks: Trademarks string for version resource (Windows only)
        - manifest: Path to XML manifest file (Windows only)
        - uac_admin: Request elevation privileges (Windows only)
        - uac_uiaccess: Bypass UI control restrictions (Windows only)
        """

Base Executable Types

The base parameter determines the type of executable to create, with platform-specific behavior and automatic fallbacks.

# Base types (built-in)
base = "console"     # Console application (default)
base = "gui"         # GUI application (Windows/macOS)
base = "service"     # Windows service (Windows only)

# Custom base (absolute path)
base = "/path/to/custom/base"

Properties and Methods

Access and modify executable configuration through properties that handle validation and platform-specific logic.

# Key properties
@property
def base(self) -> Path:
    """Path to the base executable template."""

@property  
def icon(self) -> Path | None:
    """Path to icon file with automatic extension detection."""

@property
def init_script(self) -> Path:
    """Path to initialization script."""

@property
def main_script(self) -> Path:
    """Path to main Python script."""

@property
def target_name(self) -> str:
    """Final executable name with platform extension."""

@property
def init_module_name(self) -> str:
    """Name of init module in zip file."""

@property
def main_module_name(self) -> str:
    """Name of main module in zip file."""

# Representation
def __repr__(self) -> str:
    """String representation showing script path."""

Usage Examples

from cx_Freeze import Executable

# Basic console application
exe = Executable("main.py")

# GUI application with icon
exe = Executable(
    script="gui_app.py",
    base="gui",
    icon="app_icon",  # Will search for .ico/.icns/.png/.svg
    target_name="MyApplication"
)

# Windows service with metadata
exe = Executable(
    script="service.py",
    base="service",
    target_name="MyService",
    copyright="© 2024 My Company",
    trademarks="MyApp™",
    uac_admin=True
)

# Custom initialization
exe = Executable(
    script="main.py",
    init_script="custom_init.py",
    base="console"
)

Validation

Executable configurations are validated automatically and can be validated explicitly for setup distributions.

def validate_executables(
    dist: Distribution, 
    attr: str, 
    value: list[Executable | dict | str]
) -> None:
    """
    Validate executables attribute for setup() function.

    Parameters:
    - dist: setuptools Distribution object
    - attr: Attribute name being validated
    - value: List of Executable objects, dictionaries, or script strings

    Raises:
    - SetupError: If validation fails

    Notes:
    - Accepts Executable objects, dictionaries (converted to Executable), or strings (script paths)
    - Automatically converts and normalizes input formats
    - Called automatically by setup() function
    """

Platform-Specific Behavior

Base executable selection and features vary by platform with automatic fallbacks for unsupported options.

Windows/MinGW:

  • Supports all base types: console, gui, service
  • Icon files: .ico preferred, .png/.svg supported
  • Manifest and UAC options available
  • Version resource metadata (copyright, trademarks)

macOS:

  • GUI base creates .app bundle structure
  • Service/gui bases fall back to console on non-Windows
  • Icon files: .icns preferred, .png/.svg supported
  • App bundle metadata integration

Linux:

  • All bases default to console executable
  • Icon files: .png/.svg supported
  • Desktop integration through distribution commands

Error Handling

# Common exceptions during executable configuration
class OptionError(Exception):
    """Raised for invalid executable configuration options."""

# Example error conditions:
# - Base executable not found
# - Invalid target_name (contains path separators)  
# - Icon file not found
# - Invalid init_script path

Executable Validation

Validates executable configurations to ensure they meet cx_Freeze requirements.

def validate_executables(dist: Distribution, attr: str, value) -> None:
    """
    Verify that value is a valid executables attribute.
    
    Parameters:
    - dist: setuptools Distribution object
    - attr: Attribute name being validated
    - value: Executables list to validate (Executable objects, dicts, or strings)
    
    Raises:
    - SetupError: If executables list is invalid or contains unsupported types
    
    Accepts:
    - List of Executable objects
    - List of dictionaries with executable configuration
    - List of script paths as strings
    """

Install with Tessl CLI

npx tessl i tessl/pypi-cx-freeze

docs

advanced-freezing.md

build-commands.md

cli-tools.md

distribution-commands.md

executable-config.md

index.md

tile.json