Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:\Users\jinju\AppData\Local\Programs\Python\Python35-32\lib\encodings\__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:\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)

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.

like image 949
Minha Armada Ju Avatar asked Nov 10 '17 13:11

Minha Armada Ju


2 Answers

This was a bug in cx_Freeze which has now been corrected: https://github.com/anthony-tuininga/cx_Freeze/commit/9c98492911d4c75587d3687206d11812b48bf144

like image 62
Anthony Tuininga Avatar answered Sep 21 '22 04:09

Anthony Tuininga


A simple approach but not elegant can be to place

if not True:
    import codecs

somewhere in your code.

like image 30
Michael Butscher Avatar answered Sep 20 '22 04:09

Michael Butscher