昨天重裝Python2.7.6時,爲了安裝第三方庫,我去下pip。爲了裝pip,又得先裝 ez_setup.py。結果裝ez_setup時,遇到了問題,報錯:html
[html] view plaincopypython
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128) bootstrap
Something went wrong during the installation. windows
See the error message above. spa
網上找了一大圈,發現也有人在bitbucket提了相同的問題,同時這個stackoverflow的問題也與之相似。.net
如今發現,這應該都是同一個問題。緣由與註冊表有關,可能與某些國產軟件對註冊表的改寫的gbk格式致使python沒法進行第三方庫的安裝操做。code
解決方法:打開C:\Python27\Lib下的 mimetypes.py 文件,找到大概256行(你能夠用Notepad++的搜索功能)的htm
‘default_encoding = sys.getdefaultencoding()’。blog
在這行前面添加三行:ip
[python] view plaincopy
if sys.getdefaultencoding() != 'gbk':
reload(sys)
sys.setdefaultencoding('gbk')
default_encoding = sys.getdefaultencoding()