緣由和解決方案: 'ascii' codec can't decode byte.

昨天重裝Python2.7.6時,爲了安裝第三方庫,我去下pip。爲了裝pip,又得先裝 ez_setup.py。結果裝ez_setup時,遇到了問題,報錯:html

[html] view plaincopy在CODE上查看代碼片派生到個人代碼片python

  1. UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)  bootstrap

  2. Something went wrong during the installation.  windows

  3. 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在CODE上查看代碼片派生到個人代碼片

  1. if sys.getdefaultencoding() != 'gbk':  

  2.     reload(sys)  

  3.     sys.setdefaultencoding('gbk')  

  4. default_encoding = sys.getdefaultencoding()  

相關文章
相關標籤/搜索