Create standalone executables from Python scripts
npx @tessl/cli install tessl/pypi-cx-freeze@8.4.0A cross-platform Python package that creates standalone executables from Python scripts, maintaining the same performance as the original script. cx_Freeze provides a comprehensive build system for packaging Python applications into distributable executables for Windows, macOS, and Linux platforms.
pip install cx_Freezeimport cx_Freeze
from cx_Freeze import setup, ExecutableFor specific functionality:
from cx_Freeze import (
setup, Executable, Freezer, ConstantsModule,
build_exe, ModuleFinder, Module, __version__
)from cx_Freeze import setup, Executable
# Define executable to create
executables = [
Executable("main.py", base="console")
]
# Setup configuration
setup(
name="MyApp",
version="1.0",
description="My Application",
executables=executables,
options={
"build_exe": {
"packages": ["tkinter"],
"excludes": ["unittest"],
"include_files": ["data/"]
}
}
)Command-line usage:
# Basic freezing
cxfreeze --script main.py --target-dir dist
# With options
cxfreeze --script main.py --base gui --icon app.ico --target-dir dist
# Using setup.py
python setup.py build_exe
# Create MSI installer (Windows)
python setup.py bdist_msicx_Freeze operates through several key components:
The freezing process works by:
The fundamental capability for defining and creating executable files from Python scripts, with support for different base types, icons, and metadata configuration.
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,
)
def setup(**attrs) -> setuptools.DistributionSetuptools-compatible build commands for creating executables and managing the freezing process with extensive configuration options.
class build_exe(Command):
def initialize_options(self) -> None
def finalize_options(self) -> None
def run(self) -> NoneInstallation commands for deploying built executables and managing the installation process with customizable directory options.
class install(Command):
"""Install everything from build directory."""
class install_exe(Command):
"""Install executables built from Python scripts."""Creation of platform-native installers and packages including MSI files for Windows, DMG and app bundles for macOS, and AppImages, DEBs, and RPMs for Linux.
# Windows
class bdist_msi(Command): ...
# macOS
class bdist_dmg(Command): ...
class bdist_mac(Command): ...
# Linux
class bdist_appimage(Command): ...
class bdist_deb(Command): ...
class bdist_rpm(Command): ...Complete command-line tools for freezing scripts and generating setup configurations without requiring Python programming.
def main() -> None # cxfreeze command
def main() -> None # cxfreeze-quickstart commandDirect access to the freezing engine for programmatic control over module discovery, dependency analysis, and executable creation.
class Freezer:
def __init__(
self,
executables: Sequence[Executable, Mapping[str, str], str],
constants_module: ConstantsModule | None = None,
includes: list[str] | None = None,
excludes: list[str] | None = None,
packages: list[str] | None = None,
# ... additional configuration
)
class ModuleFinder:
# Module discovery and analysis methods
class Module:
# Module representation and manipulation# Core exception types
class OptionError(Exception):
"""Raised when an error is detected in configuration."""
class SetupError(Exception):
"""Raised for setup script errors."""
class ModuleError(Exception):
"""Raised when there are problems loading modules."""
class FileError(Exception):
"""Raised for file/resource not found errors."""
class BindError(Exception):
"""Raised for Windows resource binding errors (Windows only)."""
# Platform-specific types (Windows only)
HANDLE = int | None # Windows resource handle type