When cx_Freeze packages python, UnicodeDecodeError: 'utf8 ′.... Problem Solving

Source: Internet
Author: User

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.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.