본문 바로가기

리눅스

[WIP] 우분투 18.04 LTS에서 Python 3.9 설치 및 기본 설정 방법

728x90

우분투 18.04 LTS에서 Python 3.9 설치 및 기본 설정 방법

우분투 18.04 기본 Python 버전은 3.6.9입니다. 하지만 최신 라이브러리 호환을 위해 Python 3.9 이상이 필요한 경우가 많습니다.

1. 테스트 환경

운영체제 정보

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Architecture 정보

$ getconf LONG_BIT
64

기본 Python 버전

python3 -V

or

python --version
$ python --version
Python 3.6.9

2. 데드스네이크(deadsnakes) 저장소 추가

우분투 기본 저장소에는 Python 3.9이 포함되어 있지 않기 때문에 외부 PPA를 사용합니다.

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:
https://github.com/deadsnakes/issues/issues

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
deadsnakes는 비공식 저장소이므로 운영 환경에서는 검증 후 사용 권장

3. Python 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:
  libllvm9
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
...
728x90

4. python3 기본 버전 변경 (선택 사항)

update-alternatives

  • 이전 python 버전과 신규 python 버전을 update-alternatives 명령으로 추가
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 default version 업데이트

  • 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 --version
Python 3.9.12

5. pip 설치 및 최신화

우분투 18.04 기본 pip는 오래된 버전이므로 반드시 업데이트합니다.

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으로 업그레이드하는 방법

 

728x90