如何在 Ubuntu 20.04 中为 Python2.7 安装 pip

Bhi*_*sen 6 python pip python-2.7 ubuntu-20.04

有什么办法可以为“Python2.7”安装“pip”?我可以通过以下方式安装 python2.7

sudo apt install python2-minimal
Run Code Online (Sandbox Code Playgroud)

我尝试为此安装 pip。

sudo apt install python-pip / python2-pip / python2.7-pip
Run Code Online (Sandbox Code Playgroud)

但没有一个工作。任何人都可以解决这个问题。

小智 15

Try this one:

sudo apt update
sudo apt install curl
sudo add-apt-repository universe
sudo apt update
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py # Fetch get-pip.py for python 2.7 
python2 get-pip.py
pip --version
Run Code Online (Sandbox Code Playgroud)

  • 为什么需要将“curl”与“sudo”一起使用? (2认同)
  • 安装“curl”*之后“sudo add-apt-repository Universe”的目的是什么? (2认同)

小智 7

Python 2 的 Pip 不包含在 Ubuntu 20.04 存储库中。

试试这个指南,它建议获取一个 Python 2.7 兼容get_pip.py并使用它来引导pip.

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
Run Code Online (Sandbox Code Playgroud)

  • 本指南在 Python 2.7 中不适用于我。必须使用此 URL 来下载 get-pip.py https://bootstrap.pypa.io/2.7/get-pip.py (4认同)