简体   繁体   中英

Executable generated with cx_freeze opens for an instant before closing

So I made an executable of my python script using cx_freeze but when I open it the window only stays for a fraction of a second before disappearing. I opened it directly with cmd and this is the error it displayed:

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 27, in <module>
    exec(code, m.__dict__)
  File "c:\users\admin\desktop\project2.py", line 1, in <module>
    import pygame
  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: 'utf8' codec can't decode byte 0x90 in position 2:     invalid start byte

When I compiled the executable it said that it hadn't imported several files from pygame, but "this may not be a problem as they may not be needed." I'm guessing this error is a product of those files not being imported but I don't know how to fix that.

I solved the problem. It seemed to be an issue with the version of Python and Pygame that I had, and after getting a more recent version of both everything worked just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM