博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pip install 各种包时出现报asciii码错误的问题
阅读量:4101 次
发布时间:2019-05-25

本文共 2031 字,大约阅读时间需要 6 分钟。

我在用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会自动运行这个文件。

转载地址:http://fwwsi.baihongyu.com/

你可能感兴趣的文章
day_21_0817_Mysql
查看>>
day-22 mysql_SQL 结构化查询语言
查看>>
MySQL关键字的些许问题
查看>>
浅谈HTML
查看>>
css基础
查看>>
HTML&CSS进阶
查看>>
Servlet进阶和JSP基础
查看>>
servlet&jsp 的使用以及jsp的历史遗留用法
查看>>
servlet中的cookie和session
查看>>
过滤器及JSP九大隐式对象
查看>>
软件(项目)的分层
查看>>
菜单树
查看>>
2019年百度校招面试题《Java开发工程师》
查看>>
Java 8 中的 Streams API 详解
查看>>
mysql基础优化
查看>>
MySQL约束笔记
查看>>
MySQL基础
查看>>
MySQL多表&事务基础笔记
查看>>
JDBC连接池&JDBCTemplate基础笔记
查看>>
oracle错误码及解决方法
查看>>