【问题标题】:ProtocalError, Connection Broken: ConnectionResetError when pip installing tensorflowProtocalError,连接断开:pip 安装 tensorflow 时出现 ConnectionResetError
【发布时间】:2021-12-28 10:06:49
【问题描述】:

我又有一个问题困扰着我。

上下文

我正在尝试安装 TensorFlow Object Detection API,这是一个相当漫长的过程。我陷入困境的一部分实际上是安装 tensorflow。我创建了一个 python venv(虚拟环境)并在我的 jupyter 笔记本上正确配置了我的内核,以便所有 pip 安装和包都保留在我的虚拟环境指示的目录中。现在我的 pip install 适用于每个包,但以下是一个问题:

问题

!pip install tensorflow==2.5.0

结果如下:

ERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcher
    yield
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\urllib3\response.py", line 519, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "C:\Program Files\Python39\lib\http\client.py", line 462, in read
    n = self.readinto(b)
  File "C:\Program Files\Python39\lib\http\client.py", line 506, in readinto
    n = self.fp.readinto(b)
  File "C:\Program Files\Python39\lib\socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "C:\Program Files\Python39\lib\ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "C:\Program Files\Python39\lib\ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\cli\base_command.py", line 164, in exc_logging_wrapper
    status = run_func(*args)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\cli\req_command.py", line 205, in wrapper
    return func(self, options, args)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\commands\install.py", line 338, in run
    requirement_set = resolver.resolve(
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 92, in resolve
    result = self._result = resolver.resolve(
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 482, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 349, in resolve
    self._add_to_criteria(self.state.criteria, r, parent=None)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 173, in _add_to_criteria
    if not criterion.candidates:
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 151, in __bool__
    return bool(self._sequence)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 155, in __bool__
    return any(self)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in <genexpr>
    return (c for c in iterator if id(c) not in self._incompatible_ids)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 47, in _iter_built
    candidate = func()
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 201, in _make_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 281, in __init__
    super().__init__(
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 156, in __init__
    self.dist = self._prepare()
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 225, in _prepare
    dist = self._prepare_distribution()
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 292, in _prepare_distribution
    return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\operations\prepare.py", line 482, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\operations\prepare.py", line 527, in _prepare_linked_requirement
    local_file = unpack_url(
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\operations\prepare.py", line 213, in unpack_url
    file = get_http_url(
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\operations\prepare.py", line 94, in get_http_url
    from_path, content_type = download(link, temp_dir.path)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\network\download.py", line 145, in __call__
    for chunk in chunks:
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\cli\progress_bars.py", line 144, in iter
    for x in it:
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_internal\network\utils.py", line 63, in response_chunks
    for chunk in response.raw.stream(
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\urllib3\response.py", line 576, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\urllib3\response.py", line 541, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "C:\Program Files\Python39\lib\contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\Chang\Desktop\tf projects\tf Object Detection\TFOD\lib\site-packages\pip\_vendor\urllib3\response.py", line 455, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
pip._vendor.urllib3.exceptions.ProtocolError: ("Connection broken: ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)", ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

我不希望任何人神奇地知道发生了什么,因为我知道我的 PC 的配置与下一个人的不同。但以防万一,我使用的是 python venv,python 3.9.7,我的 pip 版本是 21.3.1。我对这个错误的最后几行特别感兴趣。

问题

虽然我想要一个理想的解决方案,但我也只是想知道这个连接错误的潜在来源?我在我的 Windows 网络设置中关闭了代理检测,所以我不知道连接错误是从哪里来的?过去,我总是使用 anaconda 和 anaconda 环境来使用 tensorflow,而且我从来没有遇到过从 anaconda 安装 tensorflow 的问题。我不确定为什么 pip 在非蟒蛇中安装 tensorflow,python venv 给了我这样的问题。我最初认为这是 pip 的问题,但 pip 允许我安装我能想到的所有其他软件包,它只有 tensorflow 的这个特殊错误。

任何建议/帮助将不胜感激!

编辑 1 (2022-01-11)

我没有弄清楚我的错误的确切原因是什么,但我的问题消失了。发生的事情是我在我目前的居住地和我居住的地方的 WiFi 上配置了我的计算机(特别是 anaconda 和 python)。当我去一个家庭成员的家过节时发生了这个错误。

这里的差异是我家中的 tensorflow 安装失败,因此,我假设我住的地方和我家的 IP 地址之间的差异可能会在我尝试时断开连接的某个地方的 pip 中引发安全标志安装一个包。这是有道理的,因为通过 anaconda 安装到 conda 虚拟环境中可以正常工作,但只有 pip 安装给我带来了问题。

【问题讨论】:

    标签: python tensorflow exception pip


    【解决方案1】:

    默认情况下,PIP 直接从 Internet PYPI(Python 包索引)下载和安装包,并将它们安装在我们的 Python 环境中。所以你可能需要连接互联网才能下载这些轮子包(.whl)。

    Anaconda 是一个 Python 发行版,具有预构建和预配置的软件包集合。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 2021-03-21
      • 1970-01-01
      • 2019-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多