Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

python - cx_Freeze: “No module named 'codecs'” Windows 10

I am currently making a game using pygame module. I have followed the following links' directions. https://pythonprogramming.net/converting-pygame-executable-cx_freeze/

I have solved some problems such as KeyError KeyError: 'TCL_Library' when I use cx_Freeze AttributeError Attribute Error while using cx_Freeze

The build of setup.py has been done, but as I run the exe file of the game, it crashes with Fatal Python error: Py_Initialize: unable to load the file system codec

    Fatal Python error: Py_Initialize: unable to load the file system codec
Traceback (most recent call last):
  File "C:UsersjinjuAppDataLocalProgramsPythonPython35-32libencodings\__init__.py", line 31, in <module>
ImportError: No module named 'codecs'

I have read the previous questions answered in Linux kernel (cx_Freeze: "No module named 'codecs'"), but I want to know what should I do with my Windows 10 kernel.

I use Python 3.5.3 downloaded through the python homepage, cx_Freeze-5.1-cp35-cp35m-win32.whl downloaded automatically through pip, pygame 1.9.3 through downloading whl with pip.

the setup.py file

import cx_Freeze, os

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

os.environ['TCL_LIBRARY'] = r'C:UsersjinjuAppDataLocalProgramsPythonPython35-32clcl8.6'
os.environ['TK_LIBRARY'] = r'C:UsersjinjuAppDataLocalProgramsPythonPython35-32clk8.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)

I tried to look at the init.py file and the codecs.py file. When I try to import codecs,

module 'codecs' has no attribute 'register'

this thing comes out.

# Register the search_function in the Python codec registry
codecs.register(search_function)

This is the part where the error occurs in the init.py file.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...