【问题标题】:Packaging Python Cocos2D into an executable将 Python Cocos2D 打包成可执行文件
【发布时间】:2015-11-16 05:31:24
【问题描述】:

我们目前正在为 Ludum Dare 开发 Cocos2D 游戏,但在将游戏打包成某种可执行文件时遇到了问题。

我们尝试过使用 py2exe,但它似乎不起作用。我读过 py2exe 经常会导致这类库出现问题,但它们通常是可行的。但是,过去几个小时我一直在做一些研究,但似乎找不到解决方案。

这是它在执行 .exe 时给我们的错误消息,显然它无法导入 pyglet.resource 模块。

C:\Users\Jon\Documents\GitHubVisualStudio\King-of-the-Dungeon\King of the Dungeon\King of the Dungeon\dist>king_of_the_dungeon.exe
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\pyglet\__init__.py", line 351, in __getattr__
    return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'path'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "king_of_the_dungeon.py", line 1, in <module>
  File "C:\Python34\lib\site-packages\cocos2d-0.6.3-py3.4.egg\cocos\__init__.py", line 71, in <module>
    pyglet.resource.path.append(
  File "C:\Python34\lib\site-packages\pyglet\__init__.py", line 357, in __getattr__
    __import__(import_name)
ImportError: No module named 'pyglet.resource'

【问题讨论】:

    标签: python py2exe cocos2d-python


    【解决方案1】:

    我自己试过了,没问题。但我使用了 cx_freeze。 看,Py2exe 很旧,不再维护,总的来说,你最好使用 cx_freeze。

    1. 下载 cx_freeze
    2. 创建一个 setup.py 文件来创建一个 exe:

      import cx_Freeze
      # Change "App" to the name of your python script
      executables = [cx_Freeze.Executable("App.py")]
      
      cx_Freeze.setup(
          name="Sample Name",
          version = "1",
          options={"build_exe": {"packages":["pyglet", "cocos", "pygame"]}},
          executables = executables
          )
      
    3. 打开 cmd / 终端并使用 ; python setup.py build

    我只是用一个简单的游戏试了一下,编译没有问题。

    【讨论】:

    • 注意,我注意到有时我必须在选项中包含“pygame”,有时我不必。但无论如何,它将包含 pygame 依赖项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 2020-07-12
    • 2021-10-20
    • 2020-11-13
    • 2016-06-04
    相关资源
    最近更新 更多