하얀설표 블로그




리눅스에서 특정 버전의 pip를 설치하는 방법





( 수정됨)


간단한 방법

비교적 복잡한(?) 과정을 거치기 싫다면 가상환경을 만들면 된다.
파이썬 가상환경을 만드는 방법은 이 글에서 확인할 수 있다.

만약 이 방법을 사용해도 pip 사용이 불가능하거나, 가상환경 생성을 원치 않는 경우 다음 내용(특정 버전의 pip를 설치하는 방법)을 확인하면 된다.

$ . ~/py3.11/bin/activate
(py3.11) $ pip -V
pip 22.0.2 from /home/ubuntu/py3.11/lib/python3.11/site-packages/pip (python 3.11)

임시방편

또는 "python{파이썬 버전} -m pip install <module>" 명령으로 버전을 특정하여 모듈을 설치할 수 있다.
명령어가 길어지는 것을 신경쓰지 않는다면 이 방법을 사용하면 된다.

$ python3.10 -m pip install requests
$ python3.10
Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>

특정 버전의 pip를 설치하는 방법

리눅스에서 특정 버전의 pip를 설치하기 위해서는 apt install을 통하지 않고 설치를 시도해야 한다.
터미널에 다음 명령어들을 입력하는 것으로 pip 버전을 지정하여 설치할 수 있다.

$ export PATH="$HOME/.local/bin:$PATH"
$ PATH=$HOME/.local/bin:$PATH
$ curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

pip 설치과정

성공적으로 설치된다면 다음과 같은 설치문구들을 확인할 수 있다.

$ export PATH="$HOME/.local/bin:$PATH"
$ PATH=$HOME/.local/bin:$PATH
$ curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Using cached pip-23.1.2-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 23.1.2
    Uninstalling pip-23.1.2:
      Successfully uninstalled pip-23.1.2
Successfully installed pip-23.1.2

$ pip3.11 -V
pip 23.1.2 from /home/ubuntu/.local/lib/python3.11/site-packages/pip (python 3.11)
$ pip -V
pip 23.1.2 from /home/ubuntu/.local/lib/python3.11/site-packages/pip (python 3.11) 

PATH를 변경하는 이유

curl 명령을 실행하기 전에 PATH를 변경하게 되는데, 그 이유는 이 작업을 수행하지 않으면 설치가 되지 않기 때문이다.
만약 PATH 변경없이 curl 명령만 수행하면 다음과 같이 pip 설치에 실패한다.

$ curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Using cached pip-23.1.2-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 23.1.2
    Uninstalling pip-23.1.2:
      Successfully uninstalled pip-23.1.2
  WARNING: The scripts pip, pip3 and pip3.11 are installed in '/home/ubuntu/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.1.2

$ pip3.11 -V
Command 'pip3.11' not found, did you mean:
  command 'pip3.10' from deb python3-pip (22.0.2+dfsg-1ubuntu0.3)
Try: sudo apt install <deb name>
$ pip -V
pip 23.1.2 from /home/ubuntu/.local/lib/python3.10/site-packages/pip (python 3.10)


공감 : 0







white.seolpyo.com