cx_freeze用pygame和data文件夹编译

时间:2014-05-13 19:47:16

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

我希望使用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并导入re但是它也不起作用......

1 个答案:

答案 0 :(得分:1)

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