【发布时间】:2018-04-23 18:02:02
【问题描述】:
我目前正在使用 pygame 模块制作游戏。 我已按照以下链接的指示进行操作。 https://pythonprogramming.net/converting-pygame-executable-cx_freeze/
我已经解决了 KeyError KeyError: 'TCL_Library' when I use cx_Freeze 等一些问题 属性错误 Attribute Error while using cx_Freeze
setup.py 的构建已经完成,但是当我运行游戏的 exe 文件时,它崩溃并出现致命的 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文件中出现错误的部分。
【问题讨论】:
-
你的 quatris.py 运行没有错误不是吗?
-
即使使用
cx_freeze5.1.1 我仍然收到此错误。我一直跟踪回溯,并意识到它是一个特定的模块,它是错误的根源。就我而言,源代码是tweepy模块。我在 exe 中不需要该模块,所以我只是将其注释掉,不再出现该错误。
标签: python python-3.x pygame cx-freeze