pip下载包太久超时的话,会出现如下情况:
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
0% | | 4.1kB 17.7MB/s eta 0:00:01Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/basecommand.py", line 223, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/commands/install.py", line 282, in run
requirement_set.prepare_files(finder)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 334, in prepare_files
functools.partial(self._prepare_file, finder))
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 321, in _walk_req_to_install
more_reqs = handler(req_to_install)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 491, in _prepare_file
session=self.session)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/download.py", line 825, in unpack_url
session,
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/download.py", line 673, in unpack_http_url
from_path, content_type = _download_http_url(link, session, temp_dir)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/download.py", line 886, in _download_http_url
_download_url(resp, link, content_file)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/download.py", line 621, in _download_url
for chunk in progress_indicator(resp_read(4096), 4096):
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/utils/ui.py", line 133, in iter
for x in it:
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/download.py", line 586, in resp_read
decode_content=False):
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/_vendor/requests/packages/urllib3/response.py", line 307, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/_vendor/requests/packages/urllib3/response.py", line 267, in read
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.
解决方法有3种:
1.手动换源(推荐)
手动指定源:
在 pip 后面跟-i 来指定源,比如用豆瓣的源来安装 web.py 框架:
pip install numpy -i https://pypi.doubanio.com/simple/
注意后面要有 /simple/ 目录
推荐的源除了豆瓣之外,还推荐清华大学的tuna源:
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/
2.更改默认设置(不推荐)
需要创建或修改配置文件( linux 的文件在~/.pip/pip.conf , windows 在%HOMEPATH%\pip\pip.ini ),修改内容为:
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
如果不加后面的 install
则需要每次在命令后面加上 --trusted-host
- 手动设置延时
需要看包的大小,有时可以下载下来,有时会卡住
pip --default-timeout=100 install numpy