python 安装第三方库,超时报错--Read timed out.(亲测有效)

参考自:https://www.cnblogs.com/xiaoduc-org/p/5958973.html

1、报错如下:

Collecting keras
  Using cached https://files.pythonhosted.org/packages/5e/10/aa32dad071ce52b5502266b5c659451cfd6ffcbf14e6c8c4f16c0ff5aaab/Keras-2.2.4-py2.py3-none-any.whl
Requirement already satisfied: six>=1.9.0 in d:\pyprojects\dsj\venv\lib\site-packages (from keras)
Collecting pyyaml (from keras)
  Using cached https://files.pythonhosted.org/packages/71/f7/5513e0982417c0a497b5194cc975831755447ab5e64c5fe4c877c1706a7a/PyYAML-5.1.1-cp36-cp36m-win_amd64.whl
Requirement already satisfied: numpy>=1.9.1 in d:\pyprojects\dsj\venv\lib\site-packages (from keras)
Collecting keras-preprocessing>=1.0.5 (from keras)
  Using cached https://files.pythonhosted.org/packages/28/6a/8c1f62c37212d9fc441a7e26736df51ce6f0e38455816445471f10da4f0a/Keras_Preprocessing-1.1.0-py2.py3-none-any.whl
Collecting keras-applications>=1.0.6 (from keras)
  Using cached https://files.pythonhosted.org/packages/71/e3/19762fdfc62877ae9102edf6342d71b28fbfd9dea3d2f96a882ce099b03f/Keras_Applications-1.0.8-py3-none-any.whl
Requirement already satisfied: scipy>=0.14 in d:\pyprojects\dsj\venv\lib\site-packages (from keras)
Collecting h5py (from keras)
  Downloading https://files.pythonhosted.org/packages/01/1e/115c4403544a91001d9c618748b2e8786db45544e36b8a6cf3c525e9b57f/h5py-2.9.0-cp36-cp36m-win_amd64.whl (2.4MB)
    6% |██                              | 153kB 9.5kB/s eta 0:03:55Exception:
Traceback (most recent call last):
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\_vendor\urllib3\response.py", line 302, in _error_catcher
    yield
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\_vendor\urllib3\response.py", line 384, in read
    data = self._fp.read(amt)
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\_vendor\cachecontrol\filewrapper.py", line 60, in read
    data = self.__fp.read(amt)
  File "D:\devSoft\Python36\lib\http\client.py", line 449, in read
    n = self.readinto(b)
  File "D:\devSoft\Python36\lib\http\client.py", line 493, in readinto
    n = self.fp.readinto(b)
  File "D:\devSoft\Python36\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "D:\devSoft\Python36\lib\ssl.py", line 1009, in recv_into
    return self.read(nbytes, buffer)
  File "D:\devSoft\Python36\lib\ssl.py", line 871, in read
    return self._sslobj.read(len, buffer)
  File "D:\devSoft\Python36\lib\ssl.py", line 631, in read
    v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\commands\install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\req\req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\download.py", line 821, in unpack_url
    hashes=hashes
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\download.py", line 659, in unpack_http_url
    hashes)
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\download.py", line 882, in _download_http_url
    _download_url(resp, link, content_file, hashes)
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\download.py", line 603, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\utils\hashes.py", line 46, in check_against_chunks
    for chunk in chunks:
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\download.py", line 571, in written_chunks
    for chunk in chunks:
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\utils\ui.py", line 139, in iter
    for x in it:
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\download.py", line 560, in resp_read
    decode_content=False):
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\_vendor\urllib3\response.py", line 436, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\_vendor\urllib3\response.py", line 401, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "D:\devSoft\Python36\lib\contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "D:\pyProjects\dsj\venv\lib\site-packages\pip-9.0.3-py3.6.egg\pip\_vendor\urllib3\response.py", line 307, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

在这里插入图片描述
2、解决方法:
1)cmd, cd到项目所在文件的Scripts目录,我的目录如下图:
在这里插入图片描述
2)设置超时时间
pip --default-timeout=100 install -U Pillow
在这里插入图片描述3)在重新执行pip install xxx (xxx为你需要安装的包名称)
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值