python – cx_Freeze:“没有名为’codecs’的模块”Windows 10
作者:互联网
我目前正在使用pygame模块制作游戏.
我按照以下链接指示.
https://pythonprogramming.net/converting-pygame-executable-cx_freeze/
我已经解决了一些问题,例如KeyError KeyError: ‘TCL_Library’ when I use cx_Freeze
AttributeError的
Attribute Error while using cx_Freeze
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'
我已经阅读过Linux内核(cx_Freeze: “No module named ‘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)
我试着查看init.py文件和codecs.py文件.当我尝试导入编解码器时
module 'codecs' has no attribute 'register'
这件事出来了.
# Register the search_function in the Python codec registry
codecs.register(search_function)
这是init.py文件中发生错误的部分.
解决方法:
这是cx_Freeze中的一个错误,现已更正:https://github.com/anthony-tuininga/cx_Freeze/commit/9c98492911d4c75587d3687206d11812b48bf144
标签:python,python-3-x,pygame,cx-freeze 来源: https://codeday.me/bug/20190927/1824792.html