【问题标题】:cx_freeze compile with pygame and data foldercx_freeze 用 pygame 和 data 文件夹编译
【发布时间】:2014-05-13 19:47:15
【问题描述】:

我希望用 Pygame 1.9.5 编译我用 Python 3.2 编写的程序。但我是 cx_Freeze 的初学者,我不知道如何管理复杂的结构......我的意思是:

我的文件夹是这样的:

gamefolder:
lib:
    Menu.py (lauch the program)
    level.py
    othermodules.py
    ...
data:
    Level1.png
    otherspictures.png

所以我尝试编译,但是当我启动Main.exe时总是出错,确实我认为pygame没有加载并且路径也不是很清楚。

我希望有一个解决方案,并且有了这样的结构,这不是不可能的,因为我宁愿不重写脚本中的每条路径......

更多信息:

setup.py 脚本位于 lib 文件夹中,如下所示:

from cx_Freeze import setup, Executable
setup(
    name = "Resets",
    version = "1.0",
    description = "Jeu de plateforme - Projet ISN 2014",
    executables = [Executable("Menu.py")]
)

当我启动 Menu.exe 时出现此错误:

Traceback (most recent call last):
  File "C:\Python32\lib\site-packages\pygame\__init__.py", line 117, in <module>

    try: import pygame.display
  File "ExtensionLoader_pygame_display.py", line 22, in <module>
  File "ExtensionLoader_pygame_display.py", line 14, in __bootstrap__
  File "ExtensionLoader_pygame_surface.py", line 22, in <module>
  File "ExtensionLoader_pygame_surface.py", line 14, in __bootstrap__
ImportError: No module named _view

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
7, in <module>
    exec(code, m.__dict__)
  File "Menu.py", line 8, in <module>
  File "C:\Python32\lib\site-packages\pygame\__init__.py", line 118, in <module>

    except (ImportError,IOError):display=MissingModule("display", geterror(), 1)

  File "C:\Python32\lib\site-packages\pygame\__init__.py", line 61, in __init__
    self.warn()
  File "C:\Python32\lib\site-packages\pygame\__init__.py", line 85, in warn
    warnings.warn(message, RuntimeWarning, level)
  File "C:\Python\32-bit\3.2\lib\warnings.py", line 18, in showwarning
  File "C:\Python\32-bit\3.2\lib\warnings.py", line 25, in formatwarning
  File "C:\Python\32-bit\3.2\lib\linecache.py", line 15, in getline
  File "C:\Python\32-bit\3.2\lib\linecache.py", line 41, in getlines
  File "C:\Python\32-bit\3.2\lib\linecache.py", line 127, in updatecache
  File "C:\Python\32-bit\3.2\lib\codecs.py", line 300, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid
start byte

我已经尝试过 import pygame._view 和 import re 但它也不起作用...

【问题讨论】:

  • 你得到什么错误?常见问题解答中的 Using data files 条目可能很有用。

标签: python python-3.x pygame directory-structure cx-freeze


【解决方案1】:

终于成功了,很简单! 我在每个脚本中添加了 import pygame._view。我将数据文件夹复制到文件夹中(编译后)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多