공부하는 밍

[python/ubuntu] ubuntu에서 python 버전 변경하기 본문

IT 지식/Kubernetes

[python/ubuntu] ubuntu에서 python 버전 변경하기

밍Z 2021. 10. 30. 15:09

python 2.7에서 python 3.9로 변경하는 등 python 버전을 변경해야 할 때가 있다.

$ python --version
Python 2.7.16

이 때 아래 명령어를 사용하면 python 버전 변경이 가능하다.

(변경하고자 하는 버전이 설치되어 있다는 가정 하에)

# 1번에 python3.9 등록
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1

# 2번에 python3.9 등록
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2

그 다음에 아래 명령어를 사용하면 사용할 버전을 선택할 수 있다.

$ sudo update-alternatives --config python

There are 2 choices for the alternative python (providing /usr/bin/python).
  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.5   2         auto mode
  1            /usr/bin/python3.5   2         manual mode
* 2            /usr/bin/python3.9   1         manual mode

Press <enter> to keep the current choice[*], or type selection number:

원하는 버전 번호를 선택해주면 된다.

3.9버전을 사용하고자 하면, 2를 쓰고 enter 눌러주면 완료!

$ python --version
Python 3.9.4
Comments