pip install时报错超时(pip._vendor.requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnec)解决方案
程序员文章站
2022-03-03 21:18:37
现象今天安装pip install django时总是提示安装失败,提示超时(pip._vendor.requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.),完整错误信息如下:(venv) C:\Users\user\PycharmProjects\aijoke_DRF>pip i...
现象
今天安装pip install django时总是提示安装失败,提示超时(pip._vendor.requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
),完整错误信息如下:
(venv) C:\Users\user\PycharmProjects\aijoke_DRF>pip install django
Collecting django
Downloading https://files.pythonhosted.org/packages/ca/ab/5e004afa025a6fb640c6e983d4983e6507421ff01be224da79ab7de7a21f/Django-3.0.8-py3-none-any.whl (7.5MB)
20% |██████▌ | 1.5MB 7.1kB/s eta 0:13:57Exception:
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\_vendor\requests\packages\urllib3\response.py", line 232, in _error_catcher
yield
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\_vendor\requests\packages\urllib3\response.py", line 314, in read
data = self._fp.read(amt)
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\_vendor\cachecontrol\filewrapper.py", line 60, in read
data = self.__fp.read(amt)
File "C:\Program Files\Python37\lib\http\client.py", line 457, in read
n = self.readinto(b)
File "C:\Program Files\Python37\lib\http\client.py", line 501, in readinto
n = self.fp.readinto(b)
File "C:\Program Files\Python37\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "C:\Program Files\Python37\lib\ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "C:\Program Files\Python37\lib\ssl.py", line 929, in read
return 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 "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\commands\install.py", line 324, in run
requirement_set.prepare_files(finder)
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\req\req_set.py", line 620, in _prepare_file
session=self.session, hashes=hashes)
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\download.py", line 821, in unpack_url
hashes=hashes
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\download.py", line 659, in unpack_http_url
hashes)
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\download.py", line 882, in _download_http_url
_download_url(resp, link, content_file, hashes)
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\download.py", line 603, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\utils\hashes.py", line 46, in check_against_chunks
for chunk in chunks:
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\download.py", line 571, in written_chunks
for chunk in chunks:
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\utils\ui.py", line 139, in iter
for x in it:
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\download.py", line 560, in resp_read
decode_content=False):
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\_vendor\requests\packages\urllib3\response.py", line 357, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\_vendor\requests\packages\urllib3\response.py", line 324, in read
flush_decoder = True
File "C:\Program Files\Python37\lib\contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\user\PycharmProjects\aijoke_DRF\venv\lib\site-packages\pip-9.0.1-py3.7.egg\pip\_vendor\requests\packages\urllib3\response.py", line 237, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
问题原因
出现此错误,一般都是超时导致的,可能是因为网络卡,或者下载的文件比较大等等原因
解决方案
1.增加超时时间
pip --default-timeout=100 install -U django
2.切换国内源
pip install django -i http://pypi.douban.com/simple --trusted-host=pypi.douban.com
本文地址:https://blog.csdn.net/tl4832194/article/details/107647769