Python 使用 py2app 构建独立应用程序

Python building standalone application with py2app

正在尝试使用 py2app 构建我的应用程序。创建并写入 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'],
)

在这种情况下 main.py 导入:

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

在性能中获得正确 Alien Invasion.app 所需的图标,但在启动时出现白屏。在 Internet 上我找不到如何配置 setup.py :( 请帮忙!

我的错误是指定资源文件的完整路径。只需指定一个文件夹,如下所示:

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'],
)