1

i've recently started working with pygame and wanted to create an executable using cx_Freeze but i encounter an error every time i try to run my exe file.

Fatal Python error: initfsencoding: unable to load the file system codec
ImportError: invalid flags 1530097318 in 'encodings'

Current thread 0x000016f0 (most recent call first):

Here's my setup.py file:

import cx_Freeze


import os
os.environ['TCL_LIBRARY'] = "C:\\Python37-64\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Python37-64\\tcl\\tk8.6"

executables=[cx_Freeze.Executable('snk.py')]


cx_Freeze.setup(
    name='Snake',
    options={'build_exe':{'packages':['pygame'], 'include_files':['beep.wav', 'lost.wav', 'apple.png', 'snakehead2.png', 'apple2.png', 'tail.png', 'C:\\Windows\\Fonts\\MAGNETOB.TTF']}},
    description='Snake Game',
    executables=executables


    )

Can someone please help.

Shell1500
  • 330
  • 1
  • 5
  • 14
  • This error usually comes from mixing up Python 2 and Python 3—e.g., by having a `PYTHONHOME` environment variable pointing at your Python 2 root but then running Python 3. So, the first question is: do you have multiple Python versions on your system? Do you have a `PYTHONHOME` env variable? Or `PYTHONPATH`? – abarnert Aug 02 '18 at 17:38
  • While we're at it, do you have a `PYTHON_HOME` env variable? That _should_ do nothing, but confuses some embedding sample code that's been copied and pasted a million places, which might for all I know include `cz_Freeze`. – abarnert Aug 02 '18 at 17:40
  • See [this question](https://stackoverflow.com/questions/5694706/py-initialize-fails-unable-to-load-the-file-system-codec). I think it's not really a dup, because, while it's about the same root problem, it's about embedding Python manually in your own app, which for a `cx_Freeze` user is something that happens deep under the covers and you likely don't even know what it's doing. But much of the information is still relevant here. – abarnert Aug 02 '18 at 17:44
  • @abarnert i only have one version of python running(3.7) – Shell1500 Aug 02 '18 at 17:44
  • The next biggest possibility is still a `PYTHONHOME`/`PYTHONPATH` problem: Python isn't finding the _wrong_ `Lib` directory, but just isn't finding one at all (possibly because `cx_Freeze` isn't copying it into your executable), or that the `Lib` directory is missing either the `encodings` subdirectory, or one of the files in it (or, possibly, `codecs.py` or one of the `*codec*` dynamic libs, but it seems more likely to be something like `encodings/utf_16.py` or `encodings/cp1252.py`). Also: what is your system's default character set (aka "OEM code page")? Is it cp1252 or different? – abarnert Aug 02 '18 at 17:50
  • Anyway, please answer _all_ of the questions I asked, and read the linked question. If you just answer one of the questions and ignore the rest, there's no way to help you unless someone gets really lucky. – abarnert Aug 02 '18 at 17:51

1 Answers1

0

As I answered here.You are using python 3.7. As far as I have tested , modules like pyinstaller and cx_freeze don't seem to be working in this version. Try uninstalling your python (don't forget to backup your files before), and installing python 3.6.3 or any other python 3 version except python 3.7.

Nouman
  • 6,947
  • 7
  • 32
  • 60