`

Python报错UnicodeDecodeError: ascii codec can t decode byte 0xe0 ...解决方法

阅读更多
安装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,成功了。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics