不能再用 python 2.7 安装 pip 了吗?

col*_*orf 5 python pip eol

我想使用与 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
Run Code Online (Sandbox Code Playgroud)

Ale*_*nen 5

最新的 pip 已放弃对 Python 2 的支持,并且您无法使用 Python 2.7通过get-pip.py安装最新的 pip 。

更新:在这里找到了 Python 2.7 /sf/answers/4610658321/脚本的答案 。


你应该升级到 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
Run Code Online (Sandbox Code Playgroud)
# sudo apt-get install python-pip
# python -m pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
Run Code Online (Sandbox Code Playgroud)


小智 5

pip install --upgrade "pip < 21.0"
Run Code Online (Sandbox Code Playgroud)

  • 为什么要接受它?如果您尚未安装 pip,则不可能要求 pip 自行升级 (18认同)

ELi*_*nda 0

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

python get-pip.py 'pip==20.3.1'
Run Code Online (Sandbox Code Playgroud)

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