Python 3.9 설치, 버전 변경, pip 설정 방법

개발에 필요한 오픈소스나 라이브러리 사용에 있어서 요구하는 Python 버전을 설치하고 변경하는 일은 빈번하면서도 번거로운 작업입니다. Ubuntu 20.04 버전에서 Python 3.9 설치, 버전 변경, pip 설정 방법에 대해 알아보도록 하겠습니다.

Python 3.9 설치 방법

  • 필수 프로그램 설치
$ sudo apt update
$ sudo apt install software-properties-common
  • 리포지토리 환경 설정
$ sudo add-apt-repository ppa:deadsnakes/ppa
  • Python 3.9 설치
$ sudo apt install python3.9
  • Python 설치 확인
$ which python3.9
/usr/bin/python3.9

$ python3.9 --version
Python 3.9.6

Python 버전 변경 방법

  • Python 설치 경로 확인
$ which python3.9
/usr/bin/python3.9
  • Python 버전 등록하기
# python3.9를 3번으로 등록
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 3
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python (python) in auto mode
# python3.8를 1번으로 등록
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 3
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python (python) in auto mode
  • Python 3.8 선택하기
$ sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                      Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.9         3         auto mode
  1            /usr/bin/python3.8         1         manual mode
  3            /usr/bin/python3.9         3         manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
  • Python 버전 확인
$ python --version
Python 3.8.10

pip 설정

  • pip3.9 설치
curl <https://bootstrap.pypa.io/get-pip.py> -o get-pip.py
python3.9 get-pip.py
  • PATH 설정
echo 'export PATH=~/.local/bin/:$PATH' >> ~/.bashrc
source ~/.bashrc
  • pip3.9 설치 확인
$ pip3.9 -V
pip 24.0 from /home/user/.local/lib/python3.9/site-packages/pip (python 3.9)

$ pip -V
pip 24.0 from /home/user/.local/lib/python3.9/site-packages/pip (python 3.9)
Back to top