Code of the Day
AdvancedPublishing

Packaging concepts

Distributing a .py file requires the player to have Python and the right packages installed. Learn the options for bundling your game into something anyone can run.

Game DevAdvanced5 min read
By the end of this lesson you will be able to:
  • Explain why distributing a .py file is insufficient for most players
  • Compare PyInstaller, pygame-ce web export, and itch.io as distribution options
  • Understand what a standalone executable contains

You finished your game. Your friends want to play it. You send them the .py file. They double-click it. Nothing happens — or worse, they get a ModuleNotFoundError because they don't have pygame installed. Distributing source files works among developers. It does not work for players.

The problem

A Python game depends on:

  1. A Python interpreter — the right version (3.10? 3.11?).
  2. pygame (or pygame-ce) — installed via pip.
  3. Any other packages your game uses.
  4. Your asset files — images, sounds, fonts — in the right relative paths.

Ordinary players have none of these. Even technically proficient players shouldn't have to run pip install before playing a game.

Option 1 — PyInstaller (standalone executable)

PyInstaller analyses your Python script, finds all imported modules, and bundles them together with a Python interpreter into either:

  • A one-folder distribution (--onedir): a directory containing the executable plus all required .dll/.so files and .pyc files.
  • A one-file distribution (--onefile): a single executable that extracts itself to a temp directory at launch.

The output is a native executable (.exe on Windows, no extension on macOS/Linux). Players double-click it and the game starts — no Python installation required.

Pros: mature, well-documented, supports all platforms.
Cons: large output size (30–80 MB is typical); must build separately for each target OS; macOS code signing is required for distribution outside the App Store.

Option 2 — pygame-ce web export (Emscripten)

pygame-ce is a community fork of pygame with active development. Its web export compiles Python and pygame to WebAssembly via Emscripten, producing an HTML + JS bundle that runs in a browser.

Pros: players click a link in a browser — zero installation.
Cons: experimental as of 2025; not all pygame APIs are supported; web performance is lower than native; the build process requires Docker or the Emscripten toolchain.

Option 3 — itch.io distribution

itch.io is a free game hosting platform. You upload a ZIP of your PyInstaller build (or web export). Players download it from your game's page. The platform handles bandwidth, discovery, and optional payments.

itch.io does not care what technology your game uses — it hosts the files and provides a page. Many indie developers release their first games here at zero cost.

Build your PyInstaller executable on the same OS you intend to support. A Windows .exe built on Windows will not run on macOS. If you want multi-platform builds, use CI (e.g. GitHub Actions) with separate Windows, macOS, and Linux runners.

Where to go next

Next: PyInstaller packaging — running the actual commands, bundling assets, and writing a repeatable .spec file.

Finished reading? Mark it complete to track your progress.

On this page