【问题标题】:I can't use pip on WSL Ubuntu我不能在 WSL Ubuntu 上使用 pip
【发布时间】:2019-09-23 05:08:10
【问题描述】:

如果我尝试使用 pip 下载 Python 包,则会出现以下错误消息。

nblizz@NBLIZZ-PC:~# pip3 install flask-restful
Collecting flask-restful
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
  Could not find a version that satisfies the requirement flask-restful (from versions: )
No matching distribution found for flask-restful

这些解决方案都不起作用。

  • 重新安装 pip
  • 重新安装 WSL
  • sudo pip3 install [包]
  • pip3 install [package] with root account
  • sudo -H pip3 install [包]
  • pip install --user [包]

如何安装 pip 包而不报错?

【问题讨论】:

  • Python 在 WSL 中默认不安装。我想,你必须先安装 python3。你能检查python是否工作吗?您可以关注这里的文章以获得更多帮助 1.medium.com/@rhdzmota/… 2.medium.com/@sanajitghosh/…
  • 你能检查一下网络连接吗ping 8.8.8.8
  • @AdityaMishra 我已经将 Python 安装到 WSL 并且运行良好。 pip 是唯一的问题。
  • @WaketZheng ping 8.8.8.8 的结果是 64 bytes from 8.8.8.8: icmp_seq=1 ttl=121 time=37.7 ms
  • pip3 config list 的输出是什么?

标签: python flask pip


【解决方案1】:

我用google搜索:pip ProtocolError

有人说: 已解决问题是我的宿舍防火墙阻止了 pip (pypi.python.org)。在工作中发出相同的命令可以正确安装 python 包。

见:PIP not working - proxy - Connection aborted

如果此解决方案仍然不适合您,请详细介绍您的机器,例如

pip --versionpip3 --versionpython3 -Vpython -Vcat /etc/issue

【讨论】:

    【解决方案2】:

    更新你的点子:python -m pip install –upgrade pip;如果它已经更新,请使用以下两种方法中的任何一种:

    方法 - 我 您可以从以下链接下载二进制文件 https://www.lfd.uci.edu/~gohlke/pythonlibs/

    下载所需模块(.whl 文件)后,在下载位置打开命令提示符(您可以按 shift + 右键单击​​;在此处选择打开命令提示符/powershell)并输入pip install your-package.whl

    方法-II 转到https://pypi.org/ 并搜索所需的包。 下载后,手动将包复制到 site-packages 目录中。

    网站包有标准位置:

    • Unix(纯):前缀/lib/pythonX.Y/site-packages
    • Unix(非纯):exec-prefix/lib/pythonX.Y/site-packages
    • Windows:prefix\Lib\site-packages

    要通过这两种方法中的任何一种验证下载,请在您的控制台上使用 import 语句。

    【讨论】:

      【解决方案3】:

      原因是我的卡巴斯基应用程序。它阻止每个 pip/curl 执行。

      【讨论】:

        【解决方案4】:

        我在 WSL 中遇到了与 pip 类似但不相同的问题。 (有不同的错误消息)。

        $ pip3 install pytest
        Collecting pytest
          Cache entry deserialization failed, entry ignored
          Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23344eb8>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
          Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23a7e748>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
          Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23a7e940>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
          Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23a7e390>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
          Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23a7eb00>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
          Could not find a version that satisfies the requirement pytest (from versions: )
        No matching distribution found for pytest
        

        原来 WSL 无法连接到任何 DNS 服务器。 ping 8.8.8.8 -c 1 成功,但 ping www.google.com -c 1 导致 Temporary failure in name resolution。原因是/etc/resolv.conf 已损坏。我通过将损坏的内容替换为以下内容来修复它:

        # This file was automatically generated by WSL. To stop automatic generation of this file, remove this line.
        8.8.8.8
        4.4.4.4
        

        (使用例如 nano 进行编辑:sudo nano /etc/resolv.conf)。我在上面使用了谷歌的 DNS 服务器。如果包含第一行,WSL 应自动更新 DNS 服务器。在这个 pip 再次为我正常工作之后。

        【讨论】:

          【解决方案5】:

          我在使用 conda 环境的 WSL1 上遇到了同样的问题。最终我发现解决方案是在 conda 的 base 环境中使用与触发 pip install 命令的 conda 环境中相同的 python 版本。

          应避免使用sudo pip install(即使它看似解决了NewConnectionError 错误),因为它会全局安装软件包并会弄乱 conda 环境。

          【讨论】:

            猜你喜欢
            • 2020-07-13
            • 2023-01-04
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-01-03
            • 1970-01-01
            相关资源
            最近更新 更多