您的位置是:网站首页>Python编程Python编程

pip install报错怎么办

少儿编程网2021-07-01 14:48:30Python编程 人已围观 来源:少儿编程 -用户投稿

简介解决方法:1、ReadTimeoutError,在pip安装所在文件夹路径下,创造python文件;2、UnicodeDecodeError,在Python27Libsite-packages下建个sitecustomize.py文件。本教程操作环境:windows7系统、python3版、De

解决方法:1、ReadTimeoutError,在pip安装所在文件夹路径下,创造python文件;2、UnicodeDecodeError,在Python27Libsite-packages下建个sitecustomize.py文件。5gK少儿编程网-https://www.pxcodes.com

5gK少儿编程网-https://www.pxcodes.com

本教程操作环境:windows7系统、python3版、Dell G3电脑。5gK少儿编程网-https://www.pxcodes.com

pip install 报错问题解决5gK少儿编程网-https://www.pxcodes.com

相关免费学习推荐:python视频教程!5gK少儿编程网-https://www.pxcodes.com

有时在用pip install命令安装python库时出现红字报错5gK少儿编程网-https://www.pxcodes.com

1.报错:ReadTimeoutError: HTTPSConnectionPool(host=’pypi.python.org’, port=443): Read timed out.5gK少儿编程网-https://www.pxcodes.com

Downloading xgboost-0.6a2.tar.gz (1.2MB)
    48% |███████████████▋                | 583kB 47kB/s eta 0:00:13Exception:Traceback (most recent call last):
  File "c:python27libsite-packagespipasecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:python27libsite-packagespipcommandsinstall.py", line 335, in run
    wb.build(autobuilding=True)
  File "c:python27libsite-packagespipwheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "c:python27libsite-packagespip
eq
eq_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "c:python27libsite-packagespip
eq
eq_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "c:python27libsite-packagespipdownload.py", line 821, in unpack_url
    hashes=hashes
  File "c:python27libsite-packagespipdownload.py", line 659, in unpack_http_url
    hashes)
  File "c:python27libsite-packagespipdownload.py", line 882, in _download_http_url
    _download_url(resp, link, content_file, hashes)
  File "c:python27libsite-packagespipdownload.py", line 603, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "c:python27libsite-packagespiputilshashes.py", line 46, in check_against_chunks
    for chunk in chunks:
  File "c:python27libsite-packagespipdownload.py", line 571, in written_chunks
    for chunk in chunks:
  File "c:python27libsite-packagespiputilsui.py", line 139, in iter
    for x in it:
  File "c:python27libsite-packagespipdownload.py", line 560, in resp_read
    decode_content=False):
  File "c:python27libsite-packagespip\_vendor
equestspackagesurllib3
esponse.py", line 357, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "c:python27libsite-packagespip\_vendor
equestspackagesurllib3
esponse.py", line 324, in read
    flush_decoder = True
  File "c:python27libcontextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "c:python27libsite-packagespip\_vendor
equestspackagesurllib3
esponse.py", line 246, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.

错误原因:连不上pip的源,下载依赖包失败5gK少儿编程网-https://www.pxcodes.com

解决(推荐):在pip安装所在文件夹路径下,创造python文件(.py)5gK少儿编程网-https://www.pxcodes.com

import os  

ini="""[global] 
index-url = https://pypi.doubanio.com/simple/ 
[install] 
trusted-host=pypi.doubanio.com 
"""  pippath=os.environ["USERPROFILE"]+"\pip\"  if not os.path.exists(pippath):  
    os.mkdir(pippath)  

with open(pippath+"pip.ini","w+") as f:  
    f.write(ini)

在cmd上运行这个.py文件即可5gK少儿编程网-https://www.pxcodes.com

之后再用pip install安装指令下载速度会非常快5gK少儿编程网-https://www.pxcodes.com

2.报错:UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd3 in position 7: ordinal not in range(128)5gK少儿编程网-https://www.pxcodes.com

Exception: 
Traceback (most recent call last): 
File “c:python27libsite-packagespipasecommand.py”, line 215, in main 
status = self.run(options, args) 
File “c:python27libsite-packagespipcommandsinstall.py”, line 324, in run 
requirement_set.prepare_files(finder) 
File “c:python27libsite-packagespip
eq
eq_set.py”, line 380, in prepare_files 
ignore_dependencies=self.ignore_dependencies)) 
File “c:python27libsite-packagespip
eq
eq_set.py”, line 620, in _prepare_file 
session=self.session, hashes=hashes) 
File “c:python27libsite-packagespipdownload.py”, line 821, in unpack_url 
hashes=hashes 
File “c:python27libsite-packagespipdownload.py”, line 659, in unpack_http_url 
hashes) 
File “c:python27libsite-packagespipdownload.py”, line 880, in _download_http_url 
file_path = os.path.join(temp_dir, filename) 
File “c:python27lib
tpath.py”, line 85, in join 
result_path = result_path + p_path 
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd3 in position 7: ordinal not in range(128) 

报错原因:pip安装Python包会加载目录包含中文字符,ascii不能编码5gK少儿编程网-https://www.pxcodes.com

解决:python目录 Python27Libsite-packages 建一个文件sitecustomize.py5gK少儿编程网-https://www.pxcodes.com

import sys 
sys.setdefaultencoding('gbk')

python会自动运行这个文件

以上就是pip install报错怎么办的详细内容,更多请关注少儿编程网其它相关文章!5gK少儿编程网-https://www.pxcodes.com

来源:php中文网5gK少儿编程网-https://www.pxcodes.com


相关文章:

支持一下 ( )

上一篇:python中

下一篇:python的缩进规则是什么

Tags:pip install

pip install报错怎么办

      匿名评论
    • 评论
    人参与,条评论
    pip install报错怎么办

微信公众号

免费视频教程

先知道