๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

TIL/Linux

[Ubuntu] Python ๋ฒ„์ „๋ณ€๊ฒฝ

1. ํŒŒ์ด์ฌ ๋ฒ„์ „ ํ™•์ธ

python -V

2. ํŒŒ์ด์ฌ ๋””๋ ‰ํ† ๋ฆฌ ํ™•์ธ

ls -al /usr/bin/python

3. ์„ค์น˜ ๋œ python ํ™•์ธ

ls /usr/bin/ | grep python

4. python default๋ฒ„์ „ ๋ฐ”๊ฟ”์ฃผ๊ธฐ

sudo update-alternatives --config python
  • alternatives์— ๋ญ๊ฐ€ ๋“ฑ๋ก๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธ
  • ๋“ฑ๋ก์ด ์•ˆ๋˜์–ด ์žˆ๋‹ค๋ฉด, update-alternatives: error: no alternatives for python ์ด๋ผ๋Š” ์—๋Ÿฌ๊ฐ€ ๋œธ

5. alternatives ๋“ฑ๋ก

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
  • ls /usr/bin/ | grep python ์„ ํ†ตํ•ด ํ™•์ธํ•œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ํŒŒ์ด์ฌ ์ค‘์— ์›ํ•˜๋Š” ๊ฒƒ์„ ๋“ฑ๋ก
  • ๋งŒ์•ฝ 2.7 ๋ฒ„์ „๊ณผ 3.6๋ฒ„์ „์„ ๊ฐ–๊ณ  ์žˆ๋‹ค๋ฉด, 2.7์€ 1๋ฒˆ์œผ๋กœ, 3.6์€ 2๋ฒˆ์œผ๋กœ ์ง€์ •
  • ์ˆœ์„œ๋Š” ์ƒ๊ด€์—†์Œ, ๋‚˜์ค‘์— ์›ํ•˜๋Š” python์„ ์„ ํƒํ•˜๋Š” ์šฉ๋„

6. ๋‹ค์‹œ python default ๋ฒ„์ „ ๋ฐ”๊พธ๊ธฐ ์‹œ๋„

update-alternatives --config python
1
  • ์›ํ•˜๋Š” Selection์„ ์„ ํƒ
  • ์œ„ ์˜ˆ์‹œ๋Š” 1๋ฒˆ์„ ์„ ํƒ

7. ์ž˜ ๋ฐ”๋€Œ์—ˆ๋‚˜ ํ™•์ธ

update-alternatives --config python
  • ๋ณ„ ๋ชจ์–‘์ด 0๋ฒˆ์—์„œ 1๋ฒˆ์œผ๋กœ ์ด๋™ํ–ˆ๋‹ค๋ฉด ์ž˜ ๋ฐ”๋€ ๊ฒƒ
ls -al /usr/bin/python
ls -al /etc/alternatives/python
  • ์œ„ ๋ช…๋ น์–ด๋กœ ๊ธฐ๋ณธ ํŒŒ์ด์ฌ์˜ ์ฃผ์†Œ๋ฅผ ํ™•์ธ
  • ์›๋ž˜ /usr/bin/python3.6์ด์—ˆ๋˜ ์ฃผ์†Œ๊ฐ€ /etc/alternatives/python์œผ๋กœ ๋ณ€๊ฒฝ๋˜์–ด ์žˆ์Œ

https://mickael-k.tistory.com/92