【问题标题】:pip3 read time out errorpip3 读取超时错误
【发布时间】:2022-01-13 08:09:53
【问题描述】:

sudo pip3 install scikit-learn(任何模块实际上只是使用最近的尝试)

sudo pip3 install -U scikit-learn

sudo -H pip3 install -U scikit-learn

sudo -H pip3 --default-timeout=200 install -U scikit-learn

sudo python3 -m pip install scikit-learn

上述每个命令和任何组合都会导致相同的错误:读取超时。错误总是发生在同一点(scikit-learn 发生在 24%)。我正在使用最新版本的 pip(8.1.2),并且我使用的是 ubuntu mate 16.04。确切的错误是:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/_vendor/requests/packages/urllib3/response.py", line 228, in _error_catcher
    yield
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/_vendor/requests/packages/urllib3/response.py", line 310, in read
    data = self._fp.read(amt)
   File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/_vendor/cachecontrol/filewrapper.py", line 49, in read
     data = self.__fp.read(amt)
  File "/usr/lib/python3.5/http/client.py", line 448, in read
    n = self.readinto(b)
  File "/usr/lib/python3.5/http/client.py", line 488, in readinto
    n = self.fp.readinto(b)
  File "/usr/lib/python3.5/socket.py", line 575, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3.5/ssl.py", line 929, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/lib/python3.5/ssl.py", line 791, in read
    return self._sslobj.read(len, buffer)
  File "/usr/lib/python3.5/ssl.py", line 575, 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 "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/commands/install.py", line 310, in run
    wb.build(autobuilding=True)
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/wheel.py", line 750, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/req/req_set.py", line 370, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/req/req_set.py", line 587, in _prepare_file
    session=self.session, hashes=hashes)
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/download.py", line 810, in unpack_url
    hashes=hashes
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/download.py", line 649, in unpack_http_url
hashes)
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/download.py", line 871, in _download_http_url
_download_url(resp, link, content_file, hashes)
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/download.py", line 595, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/utils/hashes.py", line 46, in check_against_chunks
    for chunk in chunks:
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/download.py", line 563, in written_chunks
    for chunk in chunks:
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/utils/ui.py", line 139, in iter
    for x in it:
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/download.py", line 552, in resp_read
decode_content=False):
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/_vendor/requests/packages/urllib3/response.py", line 353, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/_vendor/requests/packages/urllib3/response.py", line 320, in read
    flush_decoder = True
  File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.5/dist-packages/pip-8.1.2-py3.5.egg/pip/_vendor/requests/packages/urllib3/response.py", line 233, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.

【问题讨论】:

标签: linux python-3.x ubuntu-16.04


【解决方案1】:

将默认套接字超时设置为更高的值(例如 1000 秒)应该可以解决您的问题:

pip3 install -U --timeout 1000 scikit-learn

当然,合适的超时值取决于您的连接速度和质量。请注意,套接字超时 AFAIK 是在引发错误之前套接字级数据流中断的最长时间,而不是下载包所需的总时间。

【讨论】:

    【解决方案2】:

    将超时设置为较高的值。此外,建议始终运行以下命令:

    python3 -m pip install --user --timeout 10000 scikit-learn
    

    你可能会问我为什么要额外输入 python3 -m 并输入更多的字符串。基本上是为了避免在使用多个虚拟环境时发生冲突。

    Python 核心开发人员 Brett Cannon 在他的文章 A quick and dirty guide on how to install python packages 中解释了为什么应该安装这样的包。

    【讨论】:

      【解决方案3】:

      确保您使用的是 IPV4 而不是 IPV6。

      【讨论】:

        【解决方案4】:

        有时还需要使某些主机受信任: 由于某些公司或服务提供商的代理。

        ! pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --timeout 1000 scikit-learn
        

        【讨论】:

          猜你喜欢
          • 2019-09-18
          • 1970-01-01
          • 1970-01-01
          • 2018-08-16
          • 2014-03-07
          • 2013-07-09
          • 1970-01-01
          • 2013-08-07
          • 2020-12-16
          相关资源
          最近更新 更多