Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
811 views
in Technique[技术] by (71.8m points)

python - Pygame - Compiling to exe with Cx_Freeze

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:Python32libsite-packagespygame\__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:Python32libsite-packagescx_FreezeinitscriptsConsole3.py", line 2
    7, in <module>
        exec(code, m.__dict__)
      File "Title.pyw", line 8, in <module>
      File "C:Python32libsite-packagespygame\__init__.py", line 123, in <module>

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

      File "C:Python32libsite-packagespygame\__init__.py", line 66, in __init__
        self.warn()
      File "C:Python32libsite-packagespygame\__init__.py", line 90, in warn
        warnings.warn(message, RuntimeWarning, level)
      File "C:Python32libwarnings.py", line 18, in showwarning
        file.write(formatwarning(message, category, filename, lineno, line))
      File "C:Python32libwarnings.py", line 25, in formatwarning
        line = linecache.getline(filename, lineno) if line is None else line
      File "C:Python32liblinecache.py", line 15, in getline
        lines = getlines(filename, module_globals)
      File "C:Python32liblinecache.py", line 41, in getlines
        return updatecache(filename, module_globals)
      File "C:Python32liblinecache.py", line 127, in updatecache
        lines = fp.readlines()
      File "C:Python32libcodecs.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to import pygame._view.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...