I installed a cx_Freeze 4.2.2. When using it to package a py file, it will report
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc5 in position 1602: invalid continuation byte
. I searched some articles on the internet, saying that because the script file contains Chinese characters, Chinese characters must be removed to avoid this error.
A solution was also mentioned, that is, to add the following in setup. py:
Import encodings. gbk
Import encodings. utf_8
Wait. I did not solve the problem one by one.
Finally, I suddenly remembered that the first two lines of all my python scripts were:
#! /Usr/bin/env python <br/> # coding = gb2312
Is there a problem here? I changed it
#! /Usr/bin/env python <br/> # coding = UTF-8
Modify all. py files in the project and run setup. py build. The packaging process is normal, the exe program runs normally, and the Chinese characters are displayed normally.
It seems that the cause for the prompt UnicodeDecodeError: 'utf8' codec... is that the Chinese character encoding format specified by the script itself is inconsistent with the default cx_Freeze encoding format.