UnicodeDecodeError: 'utf8' codec can't decode byte 0xb2 in position 59: invalid start byte

187 views
Skip to first unread message

Love is going on li

unread,
Jun 23, 2018, 11:34:18 AM6/23/18
to wxPython-dev

wxPython-4.0.1
PyInstaller: 3.3.1
Python: 2.7.14
Windows-10-10.0.17134

Run the command

pyinstaller helloworld
.py

Add Chinese path
..\test\dist\helloworld\   ..test\dist\helloworld_测试\


Run

G:\python_project\python\gui_wxpython\test\dist\helloworld_测试>helloworld.exe
Traceback (most recent call last):
  File "helloworld.py", line 13, in <module>
  File "site-packages\wx\core.py", line 2060, in __init__
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb2 in position 59: invalid start byte
[11712] Failed to execute script helloworld

G:\python_project\python\gui_wxpython\test\dist\helloworld_测试>

Can you help me? Thank you

Robin Dunn

unread,
Jun 23, 2018, 12:58:36 PM6/23/18
to wxPython-dev


On Saturday, June 23, 2018 at 8:34:18 AM UTC-7, Love is going on li wrote:


G:\python_project\python\gui_wxpython\test\dist\helloworld_测试>helloworld.exe
Traceback (most recent call last):
  File "helloworld.py", line 13, in <module>
  File "site-packages\wx\core.py", line 2060, in __init__
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb2 in position 59: invalid start byte
[11712] Failed to execute script helloworld

G:\python_project\python\gui_wxpython\test\dist\helloworld_测试>

Can you help me? Thank you


That line is:

         wx.StandardPaths.Get().SetInstallPrefix(_sys.prefix)

SetInstallPrefix expects to get a unicode string, or something that can be converted to unicode using the utf-8 encoding. Since you are using Python2 then sys.prefix is likely a non-unicode string and it is probably encoded using the filesystem's default encoding, which isn't utf-8.  Please try replacing that line with this code and let us know if that takes care of the problem for you.


        prefix = _sys.prefix
        if isinstance(prefix, (bytes, bytearray)):
            prefix = prefix.decode(_sys.getfilesystemencoding())
        wx.StandardPaths.Get().SetInstallPrefix(prefix)

--
Robin

Love is going on li

unread,
Jun 24, 2018, 10:56:27 PM6/24/18
to wxPython-dev
Thank you very much for your help. I can run normally.

 
Reply all
Reply to author
Forward
0 new messages