본문 바로가기
IT/IT 잡지식

파이썬 버전 업그레이드 후 버젼별 사용 설정하기

by 큰공 2020. 12. 7.
728x90
반응형

 

개요

  리눅스 환경 빌드시스템 구축 중 아래와 같은 에러메시지가 출력될때, 파이썬 업그레이드를 하는 방법에 대해서 기술한다.

 repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.

 

설치

$ sudo apt-get install python3.6

 

벌써 설치 되었다고?

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3.6 is already the newest version (3.6.9-1~18.04ubuntu1.3).
python3.6 set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 112 not upgraded.

 오잉? 설치를 할려고 했더니 벌써 설치가 되어 있다고 한다.

 

근데 왜 예전 버젼으로 동작하지?

$ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

 phthon 을 실행해보면 이전 버젼으로 동작 한다.

 

Alternatives 를 이용한 버젼 사용 설정

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

$ python
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

 

다시 이전 버젼으로 돌리고 싶다면?

$ 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.6   1         auto mode
  1            /usr/bin/python2.7   1         manual mode
* 2            /usr/bin/python3.6   1         manual mode

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

update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode



$ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

 cofing 옵션을 선택한 다음, Selection 에서 이전 버젼인 1 을 선택하면, 다시 2.7 버젼으로 돌아 갔음을 확인 할 수 있다.

 

결론

 파이썬을 최신 버젼으로 설치 했지만, 최신 버젼이 동작하지 않을 경우 "update-alternatives" 설정으로 버전을 선택 하자.

 

 

728x90
반응형

댓글