无法再使用 python 2.7 安装 pip?

问题描述 投票:0回答:9

我想使用与 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 pip eol
9个回答
17
投票
pip install --upgrade "pip < 21.0"

7
投票

最新的 pip 放弃了对 Python 2 的支持 而且您不能使用 Python 2.7. 通过 get-pip.py

安装最新的 pip

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


你应该升级到 Python 3。 如果你使用的是只有 Python2.7 的 Linux 发行版,你可以使用你的 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 已经放弃了对 python 2.7 的支持。如果你仍然想将它用于 python 2.7,降级 pip 将帮助你:

sudo easy_install pip==20.3.4

3
投票

一个可行的解决方案:

  1. 已安装 python2

  2. 已安装 python3(是 3)

  3. 安装旧版 pip 到 python3(例如 9):

    python3 -m pip install --upgrade "pip==9"

  4. 找到它已安装到的位置:

    python3 -m pip show pip

  5. 复制到python2的路径:

    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。


3
投票

另一个基于

get-pip.py
的工作解决方案,它不会降级 python3 pip 版本:

curl 'https://raw.githubusercontent.com/pypa/get-pip/20.3.4/get-pip.py' -o get-pip.py
python2 get-pip.py

说明:pip 21.0 已于 2021 年 1 月放弃对 Python 2.7 的支持


0
投票

问题似乎是没有指定

pip
的特定版本,因此,脚本正在尝试安装最新版本(21或更高版本)。尝试指定一个旧版本,例如

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

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


0
投票
  1. 这个脚本兼容Python 2.7吗?尝试将脚本更新为未弃用的版本,然后运行它。

  2. 打开 Python 2.7 安装程序,转到高级选项并查找“安装

    pip
    ”复选标记,因为在更高版本的 Python 中,高级选项中确实带有“安装
    pip
    ”复选标记。

  3. 尝试通过手动方法获取模块,即在所需模块的网站上查找并安装到

    C:\Python27\Scripts
    .

如果以上解决方案都没有帮助,建议您参考这篇文章。我会通知您,自 2020 年 1 月 1 日起,Python 2.7 已被视为已弃用。


0
投票

PIP 可以使用下面的命令安装在 python2.7 中

python2.7 -m ensurepip --default-pip

-1
投票

没有一个建议的解决方案对我有用......

© www.soinside.com 2019 - 2024. All rights reserved.