Python run code appears ' ASCII ' codec can ' t decode byte 0xb4 in position 11:ordinal not in range (128)

Source: Internet
Author: User

Learning machine learning problems arise, Baidu has not finished a half-day, but know the reason for the following reasons:

Because Python uses ASCII encoding by default, and when Python converts between encodings, the Unicode As an "intermediate code", but Unicode is only 128 that long, so this error is reported here when attempting to convert an ASCII-encoded string to "intermediate encoded" Unicode because it is out of range.

Now that you know the reason, it's OK. Not

The workaround is as follows:

1. Modify the default encoding format: For example # encoding =utf-8

2. In/usr/lib/python2.7/ Add a sitecustomize.py file under the site-packages/directory with the following contents:

 import  syssys.setdefaultencoding ( '  Utf-8      

3. I haven't tried the above method, but I feel I can. It is in principle a modified encoding format for all files.

But the reason I was wrong is that the path has Chinese ... Change to English is good, if have the same situation may wish to try the

Python run code appears ' ASCII ' codec can ' t decode byte 0xb4 in position 11:ordinal not in range (+)

/span>
Related Article

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.