如何在擁有 python3 的情況下使用 pip 安裝 python2 套件?

如何在擁有 python3 的情況下使用 pip 安裝 python2 套件?

我在 Parrot 作業系統上。

我安裝了 python 2 和 Python 3。

┌─[✗]─[jaysmito@parrot]─[~/]
└──╼ $python --version
Python 3.9.2
┌─[jaysmito@parrot]─[~/]
└──╼ $python2 --version
Python 2.7.18

和點:

┌─[✗]─[jaysmito@parrot]─[~/]
└──╼ $pip --version
pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)
┌─[jaysmito@parrot]─[~/]
└──╼ $pip3 --version
pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)

我想安裝 python2 的包,但已經安裝了 python 3 的包

┌─[jaysmito@parrot]─[~/]
└──╼ $pip install xdg
Requirement already satisfied: xdg in /usr/lib/python3/dist-packages (5)
┌─[jaysmito@parrot]─[~/]
└──╼ $pip3 install xdg
Requirement already satisfied: xdg in /usr/lib/python3/dist-packages (5)
┌─[jaysmito@parrot]─[~/]
└──╼ $python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xdg
>>> exit()
┌─[jaysmito@parrot]─[~/]
└──╼ $python2
Python 2.7.18 (default, Mar  9 2021, 11:09:26) 
[GCC 10.2.1 20210110] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xdg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named xdg

我該如何解決這個問題?

答案1

你只有pippython3。要為 python2 安裝它,您需要透過套件管理器安裝它或從 url 安裝腳本

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python2 get-pip.py

你現在應該已經為 python2 安裝了 pip 。

相關內容