在Ubuntu 20.04上安装pip2

11

在Ubuntu 20.04成功安装Python2后,通过以下命令下载get-pip.py: sudo apt install python2

https://bootstrap.pypa.io/get-pip.py下载get-pip.py, sha256: ffb67da2e976f48dd29714fc64812d1ac419eb7d48079737166dd95640d1debd

运行以下命令:

sudo python2 get-pip.py

Traceback (most recent call last):
File "get-pip.py", line 24226, in
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/tmp6DHWFv/pip.zip/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax


Python2不支持f-string,而f"ERROR: {exc}"是一个f-string。因此,这个get-pip.py适用于Python3。 - sinkmanu
略微偏离主题,但想提一下:在许多情况下,virtualenv(https://docs.python.org/3/library/venv.html)是使用除系统范围版本以外的其他Python版本的好解决方案。 - mfit
请查看 https://dev59.com/AFEG5IYBdhLWcg3wct9F#65871131 - phd
4个回答

19

你可以使用这些命令。它们现在就可用。你必须使用 Python2 进行安装。

wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python2 get-pip.py

4
这个链接已经不再维护。请使用@red所回答的https://bootstrap.pypa.io/pip/2.7/get-pip.py链接。 - Puspendu Banerjee

6

这个版本好像不起作用,所以我从以下链接下载了一个之前的版本:
https://bootstrap.pypa.io/2.6/get-pip.py。运行以下命令之后:

sudo python2 get-pip.py

pip 9.0.3 版本被安装。接下来运行

sudo pip install --upgrade pip

pip 20.3.4 被安装。现在可以使用我需要的 Python 工具了。


此 get-pip.py 文件的 sha256 值为 02b9553a4fc36740ff183c40ce413d4ae840d17099e16a43ef4f7996230ea173。 - Juan A. Muñoz

5

我会在这里发布更新后的答案。 Pip作者已经更新了链接并请求道歉。

wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python2 get-pip.py

0

这是一篇非常老的帖子,但当我搜索 ubuntu如何安装pip2 时,它是谷歌上出现的第一篇文章。我使用python3,虽然我有一个python2,但它是裸奔的。

这是我第一次使用python2的pip等效物。按照原帖提供的URL,然后用python2.7 get-pip.py运行它,我发现它在输出中给了我答案!它告诉你获取[此脚本位于https://bootstrap.pypa.io/pip/2.7/get-pip.py](https://bootstrap.pypa.io/pip/2.7/get-pip.py)并使用它代替。我不知道这是否是新的,因为这篇文章是去年发布的,但我认为提供更新的答案非常值得。

    noscere@bertram:~$ wget https://bootstrap.pypa.io/get-pip.py
    noscere@bertram:~$ chmod +x get-pip.py
    noscere@bertram:~$ python2.7 ~/bin/get-pip.py
    ERROR: This script does not work on Python 2.7 The minimum supported Python version is 3.7. Please use https://bootstrap.pypa.io/pip/2.7/get-pip.py instead.
    noscere@bertram:~$ mv get-pip.py ~/bin/get-pip3.py
    noscere@bertram:~/src/ubuntu-tweak$ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
    noscere@bertram:~$ chmod +x get-pip.py
    noscere@bertram:~$ python2.7 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.
    Collecting pip<21.0
      Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
         |████████████████████████████████| 1.5 MB 146 kB/s 
    Collecting wheel
      Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
    Installing collected packages: pip, wheel
    Successfully installed pip-20.3.4 wheel-0.37.1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接