我正在尝试使用pyinstaller生成以下“Hello world”pygame应用程序以生成Mac OS X(10.8)应用程序:
import pygame, sys
import pygame._view
from pygame.locals import *
pygame.init()
# set up the window
windowSurface = pygame.display.set_mode((500, 400), 0, 32)
pygame.display.set_caption('Hello world!')
# set up the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
# draw the white background onto the surface
windowSurface.fill(WHITE)
# draw a black circle onto the surface
pygame.draw.circle(windowSurface, BLACK, (250, 200), 20, 0)
# draw the window onto the screen
pygame.display.update()
# run the game loop
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
spec文件如下所示:
# -*- mode: python -*-
a = Analysis(['test.py'],
pathex=['/Users/ronan/Documents/projects/python/test'],
hiddenimports=[],
hookspath=None,
runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='test',
debug=True,
strip=None,
upx=False,
console=False )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=None,
upx=False,
name='test')
app = BUNDLE(coll, name='test.app')
Pyinstaller似乎做得很好,并在其中创建了一个带有test.app的dist文件夹。然而它并没有运行。当您从命令行运行dist文件夹时,会出现以下错误:
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "/Users/ronan/Documents/projects/python/test/dist/test/eggs/setuptools-0.6c12dev_r88846-py2.7.egg/pkg_resources.py", line 698, in <module>
...
LookupError: no codec search functions registered: can't find encoding
我有一个真正的挑战让Windows pyinstaller工作,但现在已经得到它。最难的部分是缺乏连贯的错误消息。我真的很喜欢python和pygame,只想跨越这个部署障碍。显然,这不是我真正的应用程序,但我认为如果我在Mac上运行这个“Hello World”,结合我在Windows上使用它所学到的知识,我应该能够解决大部分问题。另外,我想如果我弄明白这对任何其他pygame开发者都有帮助。
答案 0 :(得分:1)
使用cx_Freeze for mac
可能更好