python3을 사용하는 동안 pip를 사용하여 python2 패키지를 설치하는 방법은 무엇입니까?

python3을 사용하는 동안 pip를 사용하여 python2 패키지를 설치하는 방법은 무엇입니까?

저는 Parrot OS를 사용하고 있습니다.

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

Python3에만 해당됩니다 pip. Python2용으로 설치하려면 패키지 관리자를 통해 설치하거나 URL의 설치 스크립트를 사용해야 합니다.

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

이제 python2용 pip가 설치되어 있어야 합니다.

관련 정보