2015年12月30日 星期三

Python 3 of py2exe "UnicodeDecodeError: 'cp950' codec can't decode bytes" 可能解法

前幾天,我在執行Python 3版的py2exe出現
"UnicodeDecodeError: 'cp950' codec can't decode bytes"
錯誤,就上網Google一下可能的解法:

notepad或notepad++的utf-8編碼文件: open('filename', encoding = 'utf-8-sig') 
notepad++的utf-8 without BOM文件: open('filename', encoding = 'utf8')

 最後我把C:\Python34\Lib\site-packages\py2exe\runtime.py,
第577 line:
從原本
with open(target.script, "U") as script_file:

改成
with open(target.script, "U", encoding = 'utf-8-sig') as script_file:

就可以正常執行
py -3.4 -m py2exe myscript.py -W mysetup.py
... edit myssetup.py
py -3.4 mysetup.py py2exe

Github to GitLab or any others

https://github.com/simonchih 唉,自從github被微軟收購後,以後要慢慢改成用gitlab或其它的了…