【问题标题】:can't install pip anymore with python 2.7?不能再用 python 2.7 安装 pip 了?
【发布时间】:2021-04-09 23:19:41
【问题描述】:

我想使用兼容 python 2.7(但不是 3.8)的 python 脚本

我需要 pip 才能使脚本正常工作,但看起来我不能再安装 pip 了?我尝试使用 get-pip.py ,但它不起作用:

user@DESKTOP-J9T7UBF
$ get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
c:\users\user\appdata\local\temp\tmp2kztqk\pip.zip\pip\_vendor\urllib3\util\ssl_.py:387: SNIMissingWarning: An HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

【问题讨论】:

  • Python 2.x 已关闭,自 2021 年 1 月 1 日起不再支持和继续
  • 是的,我知道,但没有办法继续使用仅与 2.7 兼容的脚本?
  • 真的是all的输出吗?最后一行是警告,而不是错误。
  • 你可以降级你的 pip 并以这种方式安装包
  • 最好切换到Python 3。尝试docs.python.org/3/library/2to3.html转换。

标签: python pip eol


【解决方案1】:

问题似乎是没有指定pip 的特定版本,因此,脚本正在尝试安装最新版本(21 或更高版本)。尝试指定旧版本,例如

python get-pip.py 'pip==20.3.1'

记录在案:https://github.com/pypa/get-pip

【讨论】:

  • 感谢您的回答我试图指定一个旧版本,但我得到“错误:无效要求:“'pip==20.3.1'”(我尝试了不同的版本)
  • 尝试指定一个特定的 python 来运行,例如python2.7 get-pip.py
【解决方案2】:
  1. 此脚本与 Python 2.7 兼容吗?尝试将脚本更新为非弃用版本,然后运行它。

  2. 打开 Python 2.7 安装程序,转到高级选项并查找“安装pip”复选标记,因为在更高版本的 Python 中确实带有“安装pip”复选标记,在高级选项中。

  3. 尝试通过手动方法获取模块,即查看所需模块的网站并安装到C:\Python27\Scripts

如果以上解决方案都没有帮助,建议您咨询this article。我会通知您,自 2020 年 1 月 1 日起,Python 2.7 已被视为已弃用。

【讨论】:

    【解决方案3】:

    最新的 pip 有 dropped support 用于 Python 2 并且您无法使用 Python 2.7 通过get-pip.py 安装最新的 pip。

    更新:在这里找到了 Python 2.7 脚本的答案 https://stackoverflow.com/a/65866547/429476.


    您应该升级到 Python 3。 如果你使用的 Linux 发行版只有 Python2.7,你可以使用你的 Linux 包管理器。注意 - 它会安装来自上述脚本的旧版本的 Pip。

    如果您在 Linux 上通过包管理器安装了 Python,则应始终使用相同的源为该 Python 安装安装 pip。 https://pip.pypa.io/en/stable/installing/ --> https://packaging.python.org/guides/installing-using-linux-tools/

    # curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 1883k  100 1883k    0     0  6584k      0 --:--:-- --:--:-- --:--:-- 6584k
    
    # python get-pip.py --user
    
    Traceback (most recent call last):
      File "get-pip.py", line 24226, in <module>
        main()
      File "get-pip.py", line 199, in main
        bootstrap(tmpdir=tmpdir)
      File "get-pip.py", line 82, in bootstrap
        from pip._internal.cli.main import main as pip_entry_point
      File "/tmp/tmpyG_UJ3/pip.zip/pip/_internal/cli/main.py", line 60
        sys.stderr.write(f"ERROR: {exc}")
                                       ^
    SyntaxError: invalid syntax
    
    # sudo apt-get install python-pip
    # python -m pip --version
    pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
    

    【讨论】:

      【解决方案4】:
      pip install --upgrade "pip < 21.0"
      

      【讨论】:

        【解决方案5】:

        可行的解决方案:

        1. 已经安装了python2

        2. 已经安装了python3(是3)

        3. 安装一个旧的 pip 到 python3(例如 9): python3 -m pip install --upgrade "pip==9"

        4. 找到它的安装位置:python3 -m pip show pip

        5. 复制到python2的PATH:

          sudo cp -r /home/usr/.local/lib/python3.8/site-packages/pip-9.0.0.dist-info/ /usr/local/lib/python2.7/dist-packages/

          sudo cp -r /home/raczb/.local/lib/python3.8/site-packages/pip /usr/local/lib/python2.7/dist-packages/

        6. 检查:python2.7 -m pip --version

        7. 重新升级python3的pip。

        【讨论】:

          【解决方案6】:

          是的 pip 已经放弃了对 python 2.7 的支持。如果您仍想将它用于 python 2.7,降级 pip 将帮助您:

          sudo easy_install pip==20.3.4
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2014-12-22
            • 2017-02-12
            • 1970-01-01
            • 2019-06-13
            • 2021-06-04
            • 2011-10-19
            • 2017-11-06
            相关资源
            最近更新 更多