【问题标题】:KeyError when installing tensorflow安装tensorflow时出现KeyError
【发布时间】:2021-02-10 15:42:51
【问题描述】:

我尝试安装tensorflow,但我得到了这个KeyError:

>py -3.7-64 -m pip install tensorflow

Collecting tensorflow
  Downloading tensorflow-2.4.1-cp37-cp37m-win_amd64.whl (370.7 MB)
     |██                              | 20.2 MB 3.3 MB/s eta 0:01:47ERROR: Exception:
Traceback (most recent call last):
  File "C:\...\Python37\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 171, in _merge_into_criterion
    crit = self.state.criteria[name]
KeyError: 'tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\...\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcher
    yield
  File "C:\...\Python37\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:\...\Python37\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "C:\...\Python37\lib\http\client.py", line 461, in read
    n = self.readinto(b)
  File "C:\...\Python37\lib\http\client.py", line 505, in readinto
    n = self.fp.readinto(b)
  File "C:\...\Python37\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
  File "C:\...\Python37\lib\ssl.py", line 1071, in recv_into
    return self.read(nbytes, buffer)
  File "C:\...\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:\...\Python37\lib\site-packages\pip\_internal\cli\base_command.py", line 189, in _main
    status = self.run(options, args)
  File "C:\...\Python37\lib\site-packages\pip\_internal\cli\req_command.py", line 178, in wrapper
    return func(self, options, args)
  File "C:\...\Python37\lib\site-packages\pip\_internal\commands\install.py", line 317, in run
    reqs, check_supported_wheels=not options.target_dir
  File "C:\...\Python37\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 122, in resolve
    requirements, max_rounds=try_to_avoid_resolution_too_deep,
  File "C:\...\Python37\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 453, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "C:\...\Python37\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 318, in resolve
    name, crit = self._merge_into_criterion(r, parent=None)
  File "C:\...\Python37\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 173, in _merge_into_criterion
    crit = Criterion.from_requirement(self._p, requirement, parent)
  File "C:\...\Python37\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 82, in from_requirement
    if not cands:
  File "C:\...\Python37\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 124, in __bool__
    return bool(self._sequence)
  File "C:\...\Python37\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in __bool__
    return any(self)
  File "C:\...\Python37\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 38, in _iter_built
    candidate = func()
  File "C:\...\Python37\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 169, in _make_candidate_from_link
    name=name, version=version,
  File "C:\...\Python37\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 306, in __init__
    version=version,
  File "C:\...\Python37\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 144, in __init__
    self.dist = self._prepare()
  File "C:\...\Python37\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 226, in _prepare
    dist = self._prepare_distribution()
  File "C:\...\Python37\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 312, in _prepare_distribution
    self._ireq, parallel_builds=True,
  File "C:\...\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 457, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
  File "C:\...\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 482, in _prepare_linked_requirement
    self.download_dir, hashes,
  File "C:\...\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 234, in unpack_url
    hashes=hashes,
  File "C:\...\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 108, in get_http_url
    from_path, content_type = download(link, temp_dir.path)
  File "C:\...\Python37\lib\site-packages\pip\_internal\network\download.py", line 163, in __call__
    for chunk in chunks:
  File "C:\...\Python37\lib\site-packages\pip\_internal\cli\progress_bars.py", line 159, in iter
    for x in it:
  File "C:\...\Python37\lib\site-packages\pip\_internal\network\utils.py", line 88, in response_chunks
    decode_content=False,
  File "C:\...\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 576, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "C:\...\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 541, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "C:\...\Python37\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\...\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 443, 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.

然后我尝试使用虚拟环境安装它(venv),这次进度条走得更远了,但仍然抛出了几乎相同的错误。

任何想法如何解决这个问题?

谢谢。

【问题讨论】:

    标签: python tensorflow pip


    【解决方案1】:

    安装时只需使用 --default-timeout=100 参数。例如

    py -3.7-64 -m pip install --default-timeout=100 tensorflow
    

    希望对你有帮助。

    【讨论】:

    • 它将 HTTP 超时设置为 100 秒
    【解决方案2】:

    我尝试了很多方法,但都没有用。最后我必须重新安装我的 python 并且它可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 2020-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 2020-01-03
      相关资源
      最近更新 更多