您的位置:首页 > 其它

setuptools,pip,install,UnicodeDecodeError: 'ascii' codec can't decode byte.原因和解决方案

2018-03-04 15:46 981 查看
昨天重装Python2.7.6时,为了安装第三方库,我去下pip。为了装pip,又得先装 ez_setup.py。结果装ez_setup时,遇到了问题,报错:

[html] view plain copy print?UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)  
Something went wrong during the installation.  
See the error message above.  
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)
Something went wrong during the installation.
See the error message above.

网上找了一大圈,发现也有人在bitbucket提了相同的问题,同时这个stackoverflow的问题也与之类似。
现在发现,这应该都是同一个问题。原因与注册表有关,可能与某些国产软件对注册表的改写的gbk格式导致python无法进行第三方库的安装操作。

解决方法:打开C:\Python27\Lib下的 mimetypes.py 文件,找到大概256行(你可以用Notepad++的搜索功能)的
‘default_encoding = sys.getdefaultencoding()’。
在这行前面添加三行:

[python] view plain copy print?if sys.getdefaultencoding() != 'gbk':  
    reload(sys)  
    sys.setdefaultencoding('gbk')  
default_encoding = sys.getdefaultencoding()  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐