윈도우
환경 변수 편집에서 파이썬 변수의 순서를 조정해주면된다.
환경 변수 편집 방법
- 윈도우 "설정" - "시스템" - "정보"로 진입해 메뉴 하단에 있는 "고급 시스템 설정"을 실행한다.
찾는 과정이 번거롭다면 설정의 "설정 검색"창에 "고급 시스템 설정"을 검색해도 된다. - "시스템 속성"의 "고급" 탭에서 "환경 변수(N)..." 버튼을 클릭해 "환경 변수" 창을 호출한다.
- "환경 변수" - "시스템 변수(S)"에서 변수명이 "Path"인 변수를 찾아 더블클릭하거나 "편집(I)..." 버튼을 클릭해 "환경 변수 편집"창을 호출한다.
- "환경 변수 편집"에서 기본 파이썬으로 사용할 파이썬 경로를 제일 상단에 위치하게 하면 된다.
경로를 선택한 다음, "위로 이동(U)" 버튼을 클릭하여 위로 이동할 수 있다.
![윈도우 환경변수 접근방법](/media/uploads/2023.06/%ED%8C%8C%EC%9D%B4%EC%8D%AC_%EB%B3%80%EA%B2%BD_%EC%9C%88%EB%8F%84%EC%9A%B0_%EA%B2%B0%EA%B3%BC.webp)
리눅스
라즈베리파이에서 사용하는 라즈비안(raspbian) OS, 흔히 사용하는 우분투(ubuntu), 데비안(debian) 등이 linux 운영 체제에 해당한다.
update-alternatives --config 명령을 통해 python 명령시 수행할 작업을 지정할 수 있다.
다음은 2번 index로 지정된 /usr/bin/python3.10을 python 명령 기본 작업으로 설정하는 예시이다.
$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python2.7 2 auto mode
1 /usr/bin/python2.7 2 manual mode
2 /usr/bin/python3.10 1 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python (python) in manual mode
$
다시 sudo update-alternatives --config python 명령을 시도해보면 다음과 같이 기본 설정값이 변경된 것을 확인할 수 있다.
$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python2.7 2 auto mode
1 /usr/bin/python2.7 2 manual mode
* 2 /usr/bin/python3.10 1 manual mode
Press <enter> to keep the current choice[*], or type selection number:
일부 환경에서는 다음과 같은 에러가 발생할 수 는데, 이 경우에는 해결방법을 이 글에서 확인할 수 있다.
$ sudo update-alternatives --config python
update-alternatives: error: no alternatives for python
파이썬 버전 확인 방법
터미널을 실행해 "python -V" 명령어를 입력하면 기본으로 설정된 파이썬 버전이 표시된다.
만약 동일 버전의 64비트 또는 32비트 파이썬으로 변경한 것이라면 이 글을 참고해서 파이썬 비트 확인방법을 확인할 수 있다.