pip install 出現報asciii碼錯誤的問題
轉載:http://blog.csdn.NET/junli_chen/article/details/48209411
我在用pip安裝一些第三方庫時,總會報錯,錯誤如下:
提示:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb1 inposition 34: ordinal
not in range(128)
ascii編碼不能解碼問題,查了好久,糾結了好久,終於找出問題所在了。。。。。。答案在下面!
>pip install sh
Downloading/unpacking sh
Cleaning up...
Exception:
Traceback (most recent call last):
File"D:\developer\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\basecomm
and.py", line 134, in main
status = self.run(options, args)
File"D:\developer\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\commands
\install.py", line 236, in run
requirement_set.prepare_files(finder,force_root_egg_info=self.bundle, bundl
e=self.bundle)
File "D:\developer\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\req.py",
line 1092, in prepare_files
self.unpack_url(url, location,self.is_download)
File"D:\developer\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\req.py",
line 1238, in unpack_url
retval = unpack_http_url(link, location,self.download_cache, self.download_
dir)
File"D:\developer\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\download
.py", line 621, in unpack_http_url
temp_location = os.path.join(temp_dir,filename)
File "D:\developer\Python27\lib\ntpath.py",line 108, in join
path += "\\" + b
UnicodeDecodeError: 'ascii' codec can'tdecode byte 0xb1 in position 9: ordinal
not in range(128)
Traceback (most recent call last):
File"D:\developer\Python27\Scripts\pip-script.py", line 9, in<module>
load_entry_point('pip==1.4.1','console_scripts', 'pip')()
File"D:\developer\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\__init__
.py", line 148, in main
return command.main(args[1:], options)
File"D:\developer\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\basecomm
and.py", line 169, in main
text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb1 inposition 34: ordinal
not in range(128)
原因是pip安裝Python包會載入我的使用者目錄,我的使用者目錄恰好是中文的,ascii不能編碼。
解決辦法是:
python目錄 Python27\Lib\site-packages 建一個檔案sitecustomize.py
內容寫:
import sys
sys.setdefaultencoding('gbk')
python會自動執行這個檔案。