Wie installiere ich Python2-Pakete mit Pip, wenn ich Python3 habe?

Wie installiere ich Python2-Pakete mit Pip, wenn ich Python3 habe?

Ich verwende Parrot OS.

Ich habe sowohl Python 2 als auch Python 3 installiert.

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

Und pip:

┌─[✗]─[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)

Ich möchte ein Paket für Python2 installieren, aber das ist bereits für Python 3 installiert

┌─[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

Wie kann ich dieses Problem lösen?

Antwort1

Sie haben es nur pipfür Python3. Um es für Python2 zu installieren, müssen Sie es entweder über einen Paketmanager oder das Installationsskript von einer URL installieren

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

Sie sollten jetzt Pip für Python2 installiert haben.

verwandte Informationen