Previous topic

Windowing

Next topic

Diagnostics

This Page

DistributionΒΆ

You can use PyInstaller to create standalone .exe (Windows) and .app (OS X) applications. These are a great way to distribute your game to fans who may not have the technical expertise (or inclination) to install Python and other dependencies.

Note

Use the development version of PyInstaller, the current release (2.0) is too old. PyInstaller does not currently support installation via PIP or setup.py, you’ll need to just extract it and run it from its directory.

PyInstaller must be told how to package Bacon; this is done with the following bacon-hooks.py file (also included in the distributed Bacon package):

from PyInstaller.compat import is_win, is_darwin
from PyInstaller.hooks.hookutils import get_package_paths

import os
import sys
import ctypes

def collect_native_files(package, files):
    pkg_base, pkg_dir = get_package_paths(package)
    return [(os.path.join(pkg_dir, file), '') for file in files]

if is_win:
    files = ['Bacon.dll', 
             'd3dcompiler_46.dll',
             'libEGL.dll',
             'libGLESv2.dll',
             'msvcp110.dll',
             'msvcr110.dll',
             'vccorllib110.dll']
    if ctypes.sizeof(ctypes.c_void_p) == 4:
        hiddenimports = ["bacon.windows32"]
        datas = collect_native_files('bacon.windows32', files)
    else:
        hiddenimports = ["bacon.windows64"]
        datas = collect_native_files('bacon.windows64', files)
elif is_darwin:
    if ctypes.sizeof(ctypes.c_void_p) == 4:
        hiddenimports = ["bacon.darwin32"]
        files = ['Bacon.dylib']
        datas = collect_native_files('bacon.darwin32', files)
    else:
        hiddenimports = ["bacon.darwin64"]
        files = ['Bacon64.dylib']
        datas = collect_native_files('bacon.darwin64', files)

The following is an example .spec file that PyInstaller can use to build the bouncing_balls example. You can modify it to use your game’s name and resources. You must also change hookspath to point to the directory containing the above hook-bacon.py.

# -*- mode: python -*-
a = Analysis(['bouncing_balls.py'],
             pathex=['bouncing_balls'],
             hiddenimports=[],
             hookspath=None,
             runtime_hooks=None)
pyz = PYZ(a.pure)
res_tree = Tree('res', prefix='res')
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          res_tree,
          name='bouncing_balls.exe',
          debug=False,
          strip=None,
          upx=True,
          console=False)
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               #res_tree,
               strip=None,
               upx=True,
               name='dist/bouncing_balls')
app = BUNDLE(coll,
             name='bouncing_balls.app',
             icon=None)

To build run Pyinstaller with this spec file:

$ python /path/to/pyinstaller/PyInstaller.py bouncing_balls.spec --onefile

The resulting file will be built in a new dist directory.