參考鏈接http://www.111cn.net/phper/python/64627.htm
Windows10機器上安裝Python2.7後,下載一些Package包進行setup時總是報錯UnicodeDecodeError,如下:
File "C:/Python27/lib/mimetypes.py", line 250, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
在網上搜索到的解決方法如下:
1. 這是Python 2 mimetypes的bug
2. 需要將Python2.7/lib/mimetypes.py文件中如下片段註釋或刪除:
try:
ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
pass
補充其它解決辦法
解決辦法:
在報錯的頁面添加代碼: import sys
reload(sys)
sys.setdefaultencoding('utf8')
執行 Python ez_setup.py,報錯:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 35: invalid
start byte
解決辦法:
在報錯的頁面添加代碼: import sys
reload(sys)
sys.setdefaultencoding('gb18030')
然後再執行 Python ez_setup.py,成功了。