【问题标题】:Trying to create Mac OS X app from pygame hello world尝试从 pygame hello world 创建 Mac OS X 应用程序
【发布时间】:2013-05-10 00:57:30
【问题描述】:

我正在尝试使用 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,只是想跨越这个部署障碍。显然,这不是我真正的应用程序,但我认为如果我让这个“Hello World”在 Mac 上运行,结合我在 Windows 上运行所学到的知识,我应该能够弄清楚其中的大部分。另外,我认为如果我弄清楚这一点,它可能会对其他任何 pygame 开发人员有真正的帮助。

【问题讨论】:

    标签: python python-2.7 pygame pyinstaller


    【解决方案1】:

    使用 cx_Freeze for mac 可能会更好

    【讨论】:

    • 我会检查的。谢谢
    猜你喜欢
    • 2015-04-18
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    相关资源
    最近更新 更多