Building Python Games

This page is about games written in Python. A C++ game is compiled against the Acron SDK of its platform: see Building C++ Games for the Desktop.

Overview

Acron adds a build_apps command to setuptools that compiles a Python game into a self-contained program for each platform it targets. It uses pip to fetch the game’s dependencies for that platform as wheels (.whl files) – the acron wheel of the target platform first of all – freezes the game’s code and the modules it imports into an executable, and puts the executable beside the game’s files, the engine’s libraries and the plug-ins it needs. Nothing is compiled, and one machine builds for every platform: a Mac can build the Windows and Linux versions of a game, and the web and Android ones.

The companion command bdist_apps runs build_apps and then packs each platform’s build into an archive or installer: see Packaging Binaries.

Platforms

build_apps builds for the platforms the Acron archive has wheels for, named by their wheel platform tags:

win_amd64

64-bit Windows

macosx_11_0_arm64

macOS 11 or later on Apple silicon

linux_x86_64

64-bit Linux on Intel and AMD processors

emscripten_wasm32

the web (WebAssembly); see The Web

android

Android on 64-bit ARM (arm64-v8a); see Building for Android

The wheels are built for one version of Python, 3.14, and build_apps fetches wheels for the Python it runs on: run it with the project’s Python 3.14 (acronmanager does).

For linux_x86_64 it also takes the manylinux wheels of the game’s other packages (numpy, Pillow …) up to the glibc of the machine that builds: the engine’s own Linux wheel already needs that glibc. Built on macOS or Windows, where there is no glibc to ask, it takes them up to manylinux_2_28. The built app carries its Python: the interpreter’s library (libpython3.14.so.1.0) sits beside the program, which finds it there, so the app starts on a machine with no Python installed.

Without a platforms option (or -p on the command line), build_apps builds for every platform Acron publishes desktop wheels for: ['linux_x86_64', 'macosx_11_0_arm64', 'win_amd64'].

With acronmanager

In a project made by the launcher, the build options live in pyproject.toml, under [tool.acron.build_apps]:

[project]
name = "asteroids"
version = "1.0.0"
dependencies = ["acron==1.11.0.post60"]
requires-python = ">=3.14"

[tool.acron]
main_file = "src/main.py"
asset_dir = "assets/"

[tool.acron.app]
name = "Asteroids"
id = "com.example.asteroids"
icon = "art/icon.png"

[tool.acron.build_apps]
platforms = ["win_amd64", "macosx_11_0_arm64", "linux_x86_64"]
plugins = ["acrongl", "p3openal_audio"]
include_patterns = ["data/**"]
log_filename = "$USER_APPDATA/Asteroids/output.log"

and acronmanager dist (the launcher’s Distribute button) builds and packages the game:

  1. It converts the project’s assets (assets/ into .built_assets/, as acronmanager build does) and makes the app icons of [tool.acron.app] (see App Icons and Store Art).

  2. It runs bdist_apps with the options of [tool.acron.build_apps], the name and version of [project], and the icons (as icons and adaptive_icons, unless [tool.acron.build_apps] sets them). The requirements are [project] dependencies, unless the project has a requirements.txt of its own.

  3. The game’s main_file is its GUI app, named after the project, and the converted assets go with it as assets/ – under the asset directory’s name, so the game finds them there when it is frozen.

The builds are in build/<platform>/, the archives in dist/. acronmanager dist -p win_amd64 builds only the platforms it is given, and --skip-installers runs build_apps only ([tool.acron.dist] build_installers = false makes that the default). A project with a setup.py of its own is built with that file instead, and [tool.acron.build_apps] is not used.

dist --web and dist --android freeze the game the same way for the web and Android; their pages describe what differs.

pip has to find the acron wheels on the Acron archive. For the web and Android exports, acronmanager gives pip the project’s acron-archive index ([[tool.uv.index]] in pyproject.toml) with the launcher’s credentials. For a desktop build, name the index to pip yourself, as for a build by hand (below).

By hand

build_apps needs a setup.py (or setup.cfg) that describes the game and a requirements file that lists the game’s dependencies, the engine first. The requirements file pins the engine’s version, which must be the version of an acron wheel on the archive:

acron==1.11.0.post60

This setup.py packages the Asteroids sample program:

from setuptools import setup

setup(
    name='asteroids',
    version='1.0.0',
    options={
        'build_apps': {
            # Build asteroids.exe as a GUI application
            'gui_apps': {
                'asteroids': 'main.py',
            },

            # Set up output logging, important for GUI apps!
            'log_filename': '$USER_APPDATA/Asteroids/output.log',
            'log_append': False,

            # Specify which files are included with the distribution
            'include_patterns': [
                '**/*.png',
                '**/*.jpg',
                '**/*.egg',
            ],

            # Include the OpenGL renderer and OpenAL audio plug-in
            'plugins': [
                'acrongl',
                'p3openal_audio',
            ],

            # The platforms to build for
            'platforms': [
                'win_amd64',
                'macosx_11_0_arm64',
                'linux_x86_64',
            ],
        }
    }
)

acronmanager gives pip the archive (the index the project names in [[tool.uv.index]], with your sign-in). By hand, pip needs to know where the acron wheels are. The archive asks for credentials, so give pip its index with your archive read token (see Installing Acron in CI) in an environment variable, rather than in a file that is committed:

export PIP_EXTRA_INDEX_URL=https://ci:<token>@account.acronengine.com/channels/acron/pypi/simple/

(An unrelated package called acron is on PyPI; pinning the exact version, as above, keeps pip from taking it.) Then, with the project’s Python 3.14, setuptools and pip installed:

python setup.py build_apps

The resulting programs are stored in the build folder with one sub-folder per platform, together with all the files they need to run. More examples are on the Setuptools Examples page.

GUI and Console Apps

It is possible to build two kinds of executables, gui_apps and console_apps. This distinction is especially important on Windows and macOS, whereas there is no difference on other operating systems.

GUI apps are expected to be run from a file browser, start menu or straight from the desktop. They communicate back to the user via graphical windows, not via command-line output. On Windows, it is necessary to build as a GUI app to avoid a Command Prompt being opened when run. However, there is no command-line output at all on Windows or macOS when run as a GUI app! To be able to see error messages, you must set up logging to a file via log_filename, such as in the example above. On macOS, a GUI app is an app bundle (.app).

Console apps, on the other hand, are expected to be run from the command-line. On Windows, they will always spawn a Command Prompt when run. They can take command-line arguments, display output directly to the console and do not require setting log_filename.

Including Assets

Most applications have assets that need to be included separately with the application. These are not included by default, since Acron doesn’t know which files are necessary for an application or which ones are source assets or development files that should not be distributed. (acronmanager includes the converted assets of the project’s asset directory by itself.)

The include_patterns key can be used to specify a list of files or patterns to include with the application. This does not need to be used for Python files, which are compiled into the executable itself, and are not included separately. The pattern is quite flexible:

'include_patterns': [
    # Path to a specific file
    'CREDITS.txt',

    # All files in the assets/textures/ directory, but not in subdirectories
    # (use ** instead of * if that is desirable)
    'assets/textures/*',

    # All files with the .jpg extension in any subdirectory under assets/,
    # even if nested under multiple directories
    'assets/**/*.jpg',

    # A file with the .egg extension anywhere in the hierarchy
    '**/*.egg',
],

Similarly, you can define an exclude_patterns set with the same format containing files to exclude from the set above. An alternative approach is to create a pattern that includes all files, and only specify extensions to exclude using exclude_patterns.

Some extensions have special handlers associated with them. Models in .egg, .gltf and .glb files are converted to .bam files during the build (the bam_model_extensions option): BAM files are smaller and load more efficiently, and allow the loaders of those formats to be left out of the build. A converted model keeps its name with .bam added (level.glb.bam), and the game loads it by its old name.

Custom file handlers can be defined as well, as explained on the List of Build Options page.

Including Plug-Ins

Much Acron functionality is available via optional plug-ins. For example, to enable the ability to render graphics on screen, you must choose at least one of the graphics API plug-ins. Similarly, if you want to play sound and music, you need to include the OpenAL audio plug-in. The usual combination for the desktop is:

'plugins': ['acrongl', 'p3openal_audio'],
List of Plug-Ins

acrongl

OpenGL renderer (the desktop’s renderer)

acrongles2

OpenGL ES 2/3 renderer (Android)

p3tinydisplay

Software renderer

p3openal_audio

Audio (including 3D audio) support using OpenAL Soft

p3ffmpeg

Adds support for additional audio, image, and video formats beyond what is built into Acron by default. Not necessary for .ogg and .wav.

acronegg

Enables support for reading .egg files. Generally, you should not include this, since .egg files are automatically converted to .bam during build.

p3ptloader

Adds support for additional model formats. You probably want to instead add those model extensions to the bam_model_extensions list.

p3assimp

Adds support for additional model formats. You probably want to instead add those model extensions to the bam_model_extensions list.

On the web, the renderer and the audio are built into the web runtime, and the plugins option is not used.

Icons

On Windows and macOS, it is possible to change the icon that is shown in file browsers or the dock for the compiled executable. The same icon is the web page’s favicon and home screen icon, and the Android app’s launcher icon, which on Android 8 and later is better made an adaptive icon (adaptive_icons).

With acronmanager, name one picture as icon in [tool.acron.app]: it makes every size and format from it and hands them to build_apps (see App Icons and Store Art). By hand, give build_apps the images:

"gui_apps": {
    "asteroids": "src/main.py",
},
"icons": {
    # The key needs to match the key used in gui_apps/console_apps.
    # Alternatively, use "*" to set the icon for all apps.
    "asteroids": ["icon-256.png", "icon-128.png", "icon-48.png", "icon-32.png", "icon-16.png"],
},

You can provide a single image file of at least 256×256 and Acron will scale it down to smaller sizes as needed, but because automatic scaling can make the icon look illegible at smaller sizes, we highly recommend providing custom-scaled versions at resolutions 16, 32, 48, 128, and 256. Some platforms may also prefer additional resolutions, such as 24, 64, 72, 96, 144, 192, 512, and 1024.