cx_Freeze:"没有名为'codecs'的模块"Windows 10

Min*_* Ju 15 python pygame cx-freeze python-3.x

我目前正在使用pygame模块制作游戏.我按照以下链接指示. https://pythonprogramming.net/converting-pygame-executable-cx_freeze/

当我在使用cx_Freeze时使用cx_Freeze AttributeError 属性错误时,我已经解决了一些问题,例如KeyError KeyError:'TCL_Library'

setup.py的构建已经完成,但是当我运行游戏的exe文件时,它崩溃了Fatal Python错误:Py_Initialize:无法加载文件系统编解码器

    Fatal Python error: Py_Initialize: unable to load the file system codec
Traceback (most recent call last):
  File "C:\Users\jinju\AppData\Local\Programs\Python\Python35-32\lib\encodings\__init__.py", line 31, in <module>
ImportError: No module named 'codecs'
Run Code Online (Sandbox Code Playgroud)

我已经阅读过Linux内核中回答的问题(cx_Freeze:"没有名为'codecs'的模块"),但我想知道我应该如何处理Windows 10内核.

我使用通过python主页下载的Python 3.5.3,cx_Freeze-5.1-cp35-cp35m-win32.whl通过pip,pygame 1.9.3自动下载,通过pip下载whl.

setup.py文件

import cx_Freeze, os

executables = [cx_Freeze.Executable("quatris.py")]

os.environ['TCL_LIBRARY'] = r'C:\Users\jinju\AppData\Local\Programs\Python\Python35-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\jinju\AppData\Local\Programs\Python\Python35-32\tcl\tk8.6'

cx_Freeze.setup(
    name = "QUATRIS",
    version = '1.0',
    options={"build_exe": {"packages":["pygame"], "include_files":['ab_main.wav', 'ct_main.wav', 'f3_main.wav',
                                                                    'ff_main.wav', 'gta4_soviet.wav',
                                                                    'h3_neverforget.wav', 'h_onefinaleffort.wav',
                                                                    'm_sweden.wav', 'p1_stillalive.wav',
                                                                    'p2_caramiaaddio.wav', 'smb_1-up.wav',
                                                                    'smb_bump.wav', 'smb_coin.wav', 'smb_gameover.wav',
                                                                    'smb_mariodie.wav', 'smb_overworld.wav',
                                                                    'smb_pause.wav', 'tes4o_main.wav',
                                                                    'tes5s_dragonborn.wav', 'tes5s_farhorizons.wav',
                                                                    'tetris.wav', 'tloz_intro.wav', 'tw3wh_main.wav']}},
    executables = executables)
Run Code Online (Sandbox Code Playgroud)

我试着查看init .py文件和codecs.py文件.当我尝试导入编解码器时

module 'codecs' has no attribute 'register'
Run Code Online (Sandbox Code Playgroud)

这件事出来了.

# Register the search_function in the Python codec registry
codecs.register(search_function)
Run Code Online (Sandbox Code Playgroud)

这是init .py文件中发生错误的部分.

Mic*_*her 3

一个简单但不优雅的方法可以是放置

if not True:
    import codecs
Run Code Online (Sandbox Code Playgroud)

在你的代码中的某个地方。