【问题标题】:Pip can't install any packagePip 无法安装任何软件包
【发布时间】:2018-09-14 09:11:54
【问题描述】:

您好,大约 2 周前,我开始无法下载 python 包,甚至无法访问在 chrome 和 firefox 上“无法访问”的 pypi 网站。

当我尝试下载一个包时,它给了我这个:

$ python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
Collecting numpy
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy

我不知道为什么会发生这种情况,我没有在我的计算机上进行任何更改,它只是一天开始这样做,在我的两台计算机上,我不明白。 有谁知道为什么会这样?我搜索了几个小时,但找不到任何可以纠正这个错误的东西。

我尝试过的: - 卸载所有 python 程序并重新安装 - 检查我的司机(你永远不知道) - 停用任何代理 - 禁用我的防火墙

操作系统:Windows 10

【问题讨论】:

  • 你用的是什么操作系统?
  • 抱歉,忘记了,刚刚编辑过
  • 为什么要使用python -m pip install,而不是直接使用pip?在 Windows 操作系统上安装 python 时,应该有一个选项来安装额外的包。选择该选项,还选择显示如下内容的选项:“导出环境变量”。最后,您应该能够在 cmd 上简单地运行“pip install some_lib”。试试看会发生什么。
  • 它不会改变我通常使用 pip install 的任何东西,但我之所以使用它是因为这是他们说要在 numpy 网站上使用的命令
  • 无论如何它都会给出同样的错误

标签: python-3.x pip


【解决方案1】:

所以对于任何寻找解决方案的人来说,我发现这可能不是最佳的,但至少它可以工作,而不是 pip install package 使用这个命令

python.exe -m pip install package --proxy="proxy:port"

您可以在此处找到大量免费代理:https://free-proxy-list.net/(请注意,并非所有代理都有效,您可能想尝试多个,然后才能获得有效的代理)

因此,例如,您可以使用: python.exe -m pip install numpy --proxy="179.185.199.195:8080"

这行得通, 仙人掌

【讨论】:

    【解决方案2】:

    使用上一个答案中的代理将暂时使事情正常 - 如果您发现代理不会超时,但它不能解决问题,并且在大多数情况下使用代理会阻碍您的下载速度。

    我发现您需要调查您的 Python 解释器位置并确保 venv 没有引起问题。

    例如,如果 setuptools 不会更新,那么很可能已经有一部分代码或项目在持续使用 setuptools - 禁止它更新 - 并且其他软件包需要安装新版本的 setuptools。

    由于某些原因,这会导致大多数包(如 tensorflow、keras、pandas 等)出现“ConnectionResetError:现有连接被远程主机强制关闭”。

    在另一个空位置重新创建你的 venv 将重置所有包

    在 Pycharm 中执行此操作:

    File -> Settings
    Project: -> Project Interpreter
    Project Interpreter -> drop down list -> show all
    
    Remove your current Python Interpreter location
    Add New Environment
    

    然后您将被要求为您的项目放置一个位置: 在此处使用新位置将解决软件包安装的 [Win10054] ConnectionResetError。

    基本解释器:指向您的 python.exe 位置 (通常默认:C:\Users\UserProfile\AppData\Local\Programs\Python\PythonXX\python.exe 并将 XX 替换为您当前的版本,将 UserProfile 替换为您的个人资料)

    最重要的: 因为你已经设置了一个新的位置,所以先安装 setuptools,如果已经安装,然后先升级它。 之后,您可以将代码迁移到新的 venv 并且所有新包都应该可以在没有任何 connectionResetErrors 的情况下工作。

    【讨论】:

      【解决方案3】:

      pip 20.3 似乎有问题: https://github.com/pypa/pip/issues/9190 我已降级到 20.2.4,它对我有用。

      (我知道这不是最初问题的原因,但我认为当前遇到问题的人也访问了此页面)

      【讨论】:

        【解决方案4】:

        如果代理后问题仍然存在,您可能会发现 this solution 有帮助,例如:

        conn.tls_in_tls_required = False
        at \Lib\site-packages\pip\_vendor\urllib3\connectionpool.py
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-07-27
          相关资源
          最近更新 更多