pip install在Windows下报错解决

时间:2021-08-05 00:07:53

报错:

Traceback (most recent call last):

File"C:\Python27\Python27\Scripts\pip-script.py", line , in<module>

load_entry_point('pip==1.4.1','console_scripts', 'pip')()

File"C:\Python27\lib\site-packages\pip-1.4.1-py2.7.egg\pip\__init__

.py", line 148, in main

return command.main(args[:], options)

File"C:\Python27\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()

原因:
Windows的cmd环境默认为GBK编码,pip默认用UTF-8编码。
但是在Linux和Mac中,terminal环境默认的是UTF-8编码,所以不会报错。

解决方案:

python目录 Python27\Lib\site-packages 建一个文件sitecustomize.py

import sys
sys.setdefaultencoding('gbk')

python会自动运行这个文件