python2.7 in Unicodedecodeerror: ' ASCII ' codec can ' t decode byte 0

Source: Internet
Author: User

Using ez_setup.py installation Setuptools error is as follows

Traceback (most recent): File "httpservice.py", line 5, <module> import simplehttpserver File "C:\Python27\lib\SimpleHTTPServer.py", line +, in <module> class Simplehttprequesthandler ( Basehttpserver.basehttprequesthandler): File "C:\Python27\lib\SimpleHTTPServer.py", line 208, in Simplehttprequesthandler Mimetypes.init () # try to read system mime.types File "C:\Python27\lib\mimetypes.py" , Line 358, in Init db.read_windows_registry () File "C:\Python27\lib\mimetypes.py", line 258, in Read_windows_ Registry for SubkeyName in Enum_types (HKCR): File "C:\Python27\lib\mimetypes.py", line 249, in Enum_types CType = Ctype.encode (default_encoding) # Omit in 3.x! Unicodedecodeerror: ' ASCII ' codec can ' t decode byte 0xb0 in position 1:ordinal not in range (128)


Workaround:

Through the analysis of the last error prompt, is due to the Setuptools package in the setup.py encoding format error, resulting in unable to install, although the above error, but Setuptools-5.5.zip has been downloaded to complete. Then you can install the Setuptools package by hand:

1, decompression setuptools-5.5.zip to C:\Python27\Lib\site-packages\setuptools-5.5

2, modify the setup.py, add the following sentence in the code:

Modify the default encoding method

Import Sys
Reload (SYS)
Sys.setdefaultencoding (' GB18030 ')

3, at the same time, open the Python Lib folder under the mimetypes.py file, find about 256 lines of

' default_encoding = sys.getdefaultencoding () '.

Add three lines in front of this line:

    1. If sys.getdefaultencoding ()! = ' GBK ':
    2. Reload (SYS)
    3. Sys.setdefaultencoding (' GBK ')
    4. default_encoding = sys.getdefaultencoding ()

Reference: http://blog.csdn.net/scape1989/article/details/24535441

4, enter the python27\lib\site-packages\setuptools-5.5 directory in the cmd window, then enter: Python setup.py install, can be installed successfully

5. The scripts directory will then be generated in the Python installation directory, with Easy_install.exe

6. Set environment variables.

My Computer → right-click → properties → advanced → environment variable, inside the path value, add c:\Python27\Scripts


Finally, you can run Easy_install at the command line.

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.