Pygame - Compiling to exe with Cx_Freeze

随声附和 提交于 2019-12-29 09:19:08

问题


I'm trying to convert my pygame game to exe with Cx_freeze; It works fine when I run it from a script, but when I run it as an exe, it crashes with a:

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

        try: import pygame.display
      File "ExtensionLoader_pygame_display.py", line 12, in <module>
      File "ExtensionLoader_pygame_surface.py", line 12, in <module>
    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 "Title.pyw", line 8, in <module>
      File "C:\Python32\lib\site-packages\pygame\__init__.py", line 123, in <module>

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

      File "C:\Python32\lib\site-packages\pygame\__init__.py", line 66, in __init__
        self.warn()
      File "C:\Python32\lib\site-packages\pygame\__init__.py", line 90, in warn
        warnings.warn(message, RuntimeWarning, level)
      File "C:\Python32\lib\warnings.py", line 18, in showwarning
        file.write(formatwarning(message, category, filename, lineno, line))
      File "C:\Python32\lib\warnings.py", line 25, in formatwarning
        line = linecache.getline(filename, lineno) if line is None else line
      File "C:\Python32\lib\linecache.py", line 15, in getline
        lines = getlines(filename, module_globals)
      File "C:\Python32\lib\linecache.py", line 41, in getlines
        return updatecache(filename, module_globals)
      File "C:\Python32\lib\linecache.py", line 127, in updatecache
        lines = fp.readlines()
      File "C:\Python32\lib\codecs.py", line 300, in decode
        (result, consumed) = self._buffer_decode(data, self.errors, final)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0x90 in position 2: invalid s
    tart byte
    Press any key to continue . . .

Is there any way around this? Py2exe worked for some people, but since I'm using python 3, I'm out of luck on that.


回答1:


You need to import pygame._view.

There have been many questions on this, search around before you ask a question.



来源:https://stackoverflow.com/questions/7309981/pygame-compiling-to-exe-with-cx-freeze

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!