cx_Freeze

8.6.4 · active · verified Thu Apr 16

cx_Freeze is a Python package that creates standalone executables from Python scripts, providing the same performance as the original script. It is cross-platform, supporting Windows, macOS, and Linux, and is actively maintained with frequent patch and minor releases. The current version is 8.6.4, supporting Python 3.10 to 3.14.

Common errors

Warnings

Install

Imports

Quickstart

Create a `setup.py` file to configure cx_Freeze. This script specifies the main Python file to freeze, build options, included packages, and additional files. After creating `setup.py` and your main script (e.g., `hello_world.py`), run `python setup.py build` in your terminal to generate the executable. For Windows GUI applications, set `base="Win32GUI"` to prevent a console window from appearing.

import sys
from cx_Freeze import setup, Executable

# Your application's main script
main_script = "hello_world.py"

# Base for a console application, change to 'Win32GUI' for GUI apps on Windows
base = None
if sys.platform == "win32":
    base = "Win32GUI" # Or None for console application

# Options for the build_exe command
build_exe_options = {
    "packages": [], # List of packages to include
    "excludes": ["tkinter", "unittest"], # List of packages to exclude
    "include_files": [], # List of additional files to include (e.g., 'data.txt', 'images/')
    "includes": [], # Hidden imports or dynamically loaded modules
    "bin_includes": [], # Binary files dependencies
    # "include_msvcr": True # For Windows, if distributing MSVC runtime DLLs
}

# Create an Executable object
executables = [
    Executable(
        script=main_script,
        base=base,
        target_name="hello.exe" if sys.platform == "win32" else "hello",
        icon=None # Path to an .ico file for Windows executables
    )
]

# Setup function call
setup(
    name="HelloWorldApp",
    version="1.0",
    description="A simple hello world application.",
    options={"build_exe": build_exe_options},
    executables=executables
)

# To run: Save as setup.py in the same directory as hello_world.py
# Create hello_world.py with: print("Hello, cx_Freeze!")
# Then run in terminal: python setup.py build

view raw JSON →