0

When I run a script as is, and freezes it with cxFreze, I got encoding errors. After looking into it, the problem is that cxFreeze seems to go back to the 'ascii' encoding, although Python uses 'utf-8' as default.

Here's the simple script that I use:

import sys
print sys.getdefaultencoding()

Couldn't be shorter. The setup.py file:

import cx_Freeze

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

cx_Freeze.setup(
    name = 'test encoding',
    version = '0.1',
    description = "Nothing much...",
    executables = executables,
)

If I run it directly:

> python27 test_encoding.py
utf-8

But while frozen:

> build\exe.win32-2.7\test_encoding.exe
ascii

Does anyone know why it happens... and how to fix it? As you can imagine, that creates lots of errors, particularly with wxPython.

Version information:

  • Python: 2.7 (32-bit)
  • Operating system: Windows 10 (64-bit)
  • cx_Freeze: 4.3.4
vincent-lg
  • 539
  • 7
  • 15

2 Answers2

0

In Python 2.7 the default encoding is ASCII so this is expected. You'll need to find out what is changing the default encoding to UTF-8 when running Python directly -- site defaults is a likely culprit.

Anthony Tuininga
  • 6,388
  • 2
  • 14
  • 23
  • Yes... it wouldn't surprise me much. I looked into site.py though, and it seems to be ASCII, unless I change some default values that seem all to False by default. I tried to look into lib/libs/include folders in python27, to see if I could find a setdefaultencoding... but out of unittests for Twisted and site.py itself, I couldn't find anything. – vincent-lg Dec 12 '16 at 16:41
0

I found the culprit. In my case, it was Evennia, that had a customsite. For a reason I can't begin to understand, Python was looking for this file in my source folder. I deleted the directory altogether and the problem is fixed.

vincent-lg
  • 539
  • 7
  • 15