Pygame - 使用 Cx_Freeze 编译为 exe

发布于 2024-12-02 18:49:35 字数 2133 浏览 0 评论 0原文

我正在尝试使用 Cx_freeze 将我的 pygame 游戏转换为 exe;当我从脚本运行它时它工作正常,但是当我将它作为 exe 运行时,它崩溃并显示:

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 . . .

有什么办法解决这个问题吗? Py2exe 对某些人有用,但由于我使用的是 python 3,所以我不太幸运。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安稳善良 2024-12-09 18:49:35

您需要导入pygame._view

这方面的问题有很多,提问之前先搜索一下。

You need to import pygame._view.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文