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

时间:2018-04-11 14:14:09

标签: python python-3.x macos 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的性能中,但在启动时我得到一个白色屏幕。在互联网上,我找不到如何配置setup.py :(请帮忙!

1 个答案:

答案 0 :(得分:0)

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

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