Ubuntu 18.04 LTS에서 Python 3.9로 업그레이드하는 방법

Ubuntu 18.04 LTS에서 Python 3.9로 업그레이드하는 방법

테스트 환경

$ cat /etc/os-release
VERSION="18.04.6 LTS (Bionic Beaver)"
PRETTY_NAME="Ubuntu 18.04.6 LTS"

$ getconf LONG_BIT

시스템에 설치된 Python 버전

python3 -V


python --version
$ python --version
Python 3.6.9

죽은 뱀 (deadsnakes 저장소) 저장소 추가 및 업데이트

sudo add-apt-repository ppa:deadsnakes/ppa
$ add-apt-repository ppa:deadsnakes/ppa
 This PPA contains more recent Python versions packaged for Ubuntu.

Disclaimer: there's no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.

Update Note
Please use this repository instead of ppa:fkrull/deadsnakes.

Reporting Issues

Issues can be reported in the master issue tracker at:

Supported Ubuntu and Python Versions

- Ubuntu 18.04 (bionic) Python2.3 - Python 2.6, Python 3.1 - Python 3.5, Python3.7 - Python3.11
- Ubuntu 20.04 (focal) Python3.5 - Python3.7, Python3.9 - Python3.11
- Note: Python2.7 (all), Python 3.6 (bionic), Python 3.8 (focal) are not provided by deadsnakes as upstream ubuntu provides those packages.
- Note: for focal, older python versions require libssl1.0.x so they are not currently built

The packages may also work on other versions of Ubuntu or Debian, but that is not tested or supported.
sudo apt-get update
$ apt-get update
Hit:5 http://kr.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:6 http://kr.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:7 http://kr.archive.ubuntu.com/ubuntu bionic-security InRelease

파이썬 3.9 패키지 설치

apt-get install -y python3.9
$ apt-get install python3.9
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  libpython3.9-minimal libpython3.9-stdlib python3.9-minimal
Suggested packages:
  python3.9-venv binfmt-support
The following NEW packages will be installed:
  libpython3.9-minimal libpython3.9-stdlib python3.9 python3.9-minimal
0 upgraded, 4 newly installed, 0 to remove and 4 not upgraded.
Need to get 4,893 kB of archives.
After this operation, 19.1 MB of additional disk space will be used.
Do you want to continue? (Y/n) Y

업데이트 옵션

update-alternatives 명령으로 이전 Python 버전과 새 Python 버전 추가

update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
$ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in auto mode
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
$ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python3 (python3) in auto mode

Python 기본 버전 업데이트

python 3.9를 가리키도록 python 3 업데이트

update-alternatives --config python3
$ update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
* 0            /usr/bin/python3.9   2         auto mode
  1            /usr/bin/python3.6   1         manual mode
  2            /usr/bin/python3.9   2         manual mode

Press <enter> to keep the current choice(*), or type selection number: 2

파이썬 버전

$ python --version
Python 3.9.12

pip 설치(pip3 설치)

sudo apt install -y python3-pip python3.9-distutils

도트 버전

$ pip --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.9)

참조 URL

– Ubuntu 18.04 LTS에서 Python 3.9로 업그레이드하는 방법: https://scbyun.com/1218