Search code examples
pythonpython-3.xmacospy2app

Python building standalone application with py2app


Trying to build my application using py2app. Created and wrote setup.py:

from setuptools import setup

APP = ['main.py']
DATA_FILES = ['images/ship.png', 'images/ufo.png', 'fonts/a_lcdnova.ttf']
APP_NAME = "Alien Invasion"

OPTIONS = {
    'argv_emulation': True,
    'includes': ('pygame'),
    'iconfile': 'images/ship.icns'
}
setup(
    name=APP_NAME,
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

In this case main.py imports:

from Button import Button
from Enemy import Enemy
from Ship import Ship
from random import randint
import pygame
import sys

In the performance getting the right Alien Invasion.app with the desired icon, but at startup I get a white screen. On the Internet I could not find how to configure setup.py :( Please help!


Solution

  • My error was to specify the full path to the resource files. It was necessary to specify only a folder, like this:

    from setuptools import setup
    
    APP = ['main.py']
    DATA_FILES = ['images', 'fonts']
    APP_NAME = "Alien Invasion"
    
    OPTIONS = {
        'argv_emulation': True,
        'includes': ('pygame'),
        'iconfile': 'images/ship.icns'
    }
    setup(
        name=APP_NAME,
        app=APP,
        data_files=DATA_FILES,
        options={'py2app': OPTIONS},
        setup_requires=['py2app'],
    )