Tôi hiện đang tạo trò chơi bằng mô-đun pygame. Tôi đã làm theo các hướng dẫn của các liên kết sau đây. https://pythonprogramming.net/converting-pygame-executable-cx_freeze/cx_Freeze: “Không có mô-đun có tên 'codec' 'Windows 10
tôi đã giải quyết được một số vấn đề như KeyError KeyError: 'TCL_Library' when I use cx_Freeze AttributeError Attribute Error while using cx_Freeze
Việc xây dựng của setup.py đã được thực hiện, nhưng khi tôi chạy file exe của trò chơi, nó bị treo với lỗi Python Fatal : Py_Initialize: không thể tải các codec hệ thống tập tin
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'
tôi đã đọc câu hỏi trước đó đã trả lời trong Linux kernel (cx_Freeze: "No module named 'codecs'"), nhưng tôi muốn biết tôi nên làm gì với hạt nhân Windows 10 của tôi.
Tôi sử dụng Python 3.5.3 tải xuống qua trang chủ trăn, cx_Freeze-5.1-cp35-cp35m-win32.whl được tải xuống tự động thông qua pip, pygame 1.9.3 thông qua tải xuống whl bằng pip.
file 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)
tôi cố gắng nhìn vào init tập tin py và file codecs.py. Khi tôi cố gắng nhập codec,
module 'codecs' has no attribute 'register'
điều này xuất hiện.
# Register the search_function in the Python codec registry
codecs.register(search_function)
Đây là phần mà các lỗi xảy ra trong init tập tin py.
Quatris.py của bạn chạy mà không có lỗi phải không? – Simon