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

Robin Dunn <[email protected]> Sat, 23 Jun 2018 09:58:35 -0700 (PDT)
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>

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

-- 
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.