Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Python Cocos2D打包到可执行文件中_Python_Py2exe_Cocos2d Python - Fatal编程技术网

将Python Cocos2D打包到可执行文件中

将Python Cocos2D打包到可执行文件中,python,py2exe,cocos2d-python,Python,Py2exe,Cocos2d Python,我们现在正在为Ludum Dare开发一个CoCo2D游戏,我们在将游戏打包成某种可执行文件时遇到了问题 我们尝试过使用py2exe,但似乎不起作用。我已经读到py2exe经常导致此类库出现问题,但它们通常是可行的。然而,在过去的几个小时里,我一直在做一些研究,似乎找不到解决办法 下面是它在执行.exe时给我们的错误消息,显然它无法导入pyglet.resource模块 C:\Users\Jon\Documents\GitHubVisualStudio\King-of-the-Dungeon\K

我们现在正在为Ludum Dare开发一个CoCo2D游戏,我们在将游戏打包成某种可执行文件时遇到了问题

我们尝试过使用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'
C:\Users\Jon\Documents\GitHubVisualStudio\King of the Dungeon\King of the Dungeon\King of the Dungeon\dist>King of the Dungeon.exe
回溯(最近一次呼叫最后一次):
文件“C:\Python34\lib\site packages\pyglet\\uuuuu init\uuuuuu.py”,第351行,在\uuuu getattr中__
返回getattr(self.\u模块,名称)
AttributeError:“非类型”对象没有属性“路径”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“地下城之王.py”,第1行,在
文件“C:\Python34\lib\site packages\cocos2d-0.6.3-py3.4.egg\cocos\\uuuuuu init\uuuuuu.py”,第71行,在
pyglet.resource.path.append(
文件“C:\Python34\lib\site packages\pyglet\\uuuuu init\uuuuu.py”,第357行,在\uuuu getattr中__
__导入(导入名称)
ImportError:没有名为'pyglet.resource'的模块

我自己刚试过,没问题。但我用了cx\U freeze。 请看,Py2exe很旧,不再维护,总的来说,您最好使用cx\U freeze

  • 下载cx_冻结
  • 创建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
        )
    
  • 打开cmd/terminal并使用;python setup.py build构建


  • 我只是用一个简单的游戏进行了尝试,编译起来很顺利。

    注意,我注意到有时我必须在选项中包含“pygame”,有时我不必。但无论如何,它将包含pygame依赖项。