๊ด€๋ฆฌ ๋ฉ”๋‰ด

IT’s Portfolio

[Mac] Python ๊ฐœ๋ฐœํ™˜๊ฒฝ ๊ตฌ์ถ•(Miniforge, Visual Studio Code) ๋ณธ๋ฌธ

Development Study/Python

[Mac] Python ๊ฐœ๋ฐœํ™˜๊ฒฝ ๊ตฌ์ถ•(Miniforge, Visual Studio Code)

f1r3_r41n 2022. 7. 19. 12:37
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ป ๋งฅ๋ถ ํŒŒ์ด์ฌ ๊ฐœ๋ฐœํ™˜๊ฒฝ ๊ตฌ์ถ•ํ•˜๊ธฐ

์•ž์„œ ๊ฐœ๋ฐœํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•˜๊ธฐ ์ „ ์ดˆ๊ธฐ ์„ธํŒ…์„ ํ–ˆ์—ˆ๋‹ค.

์ด๋ฒˆ ๊ธ€์—์„œ๋Š” ํŒŒ์ด์ฌ ๊ฐœ๋ฐœํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•ด๋ณด๋ ค ํ•œ๋‹ค.

๐Ÿ’ก Install Python

์•ž์„œ ์„ค์น˜ํ•œ Homebrew๋ฅผ ์‚ฌ์šฉํ•ด Python์„ ์„ค์น˜ํ•  ๊ฒƒ์ด๋‹ค.

brew install python

์„ค์น˜ ํ›„ python --version ํ˜น์€ python -V, python3 -V๋กœ ๋ฒ„์ „์„ ํ™•์ธํ•˜๋ฉด ๊ธฐ์กด ๋งฅ๋ถ์— ์„ค์น˜๋˜์–ด ์žˆ๋Š” ํŒŒ์ด์ฌ ๋ฒ„์ „ 3.8์ด ๋œฐ ๊ฒƒ์ด๋‹ค.

๋•Œ๋ฌธ์— ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•ด์•ผ ์ตœ์‹  ๋ฒ„์ „์˜ ํŒŒ์ด์ฌ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ’ก Python PATH ์„ค์ •

๋‹ค์Œ์€ .bash_profile ๋‚ด์šฉ์ด๋‹ค.

alias python='python3'
export PATH=usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
1. vi ~/.bash_profile
2. open ~/.bash_profile

source ~/.bash_profile

vi ํŽธ์ง‘๊ธฐ๊ฐ€ ์ต์ˆ™ํ•œ ์‚ฌ๋žŒ์€ vi ๋ช…๋ น์–ด๋ฅผ, ์•„๋‹ˆ๋ผ๋ฉด open ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์œ„์˜ ๋‚ด์šฉ์„ ๋„ฃ๊ณ  source๋กœ ์ ์šฉํ•ด์ฃผ๋ฉด ๋˜๊ฒ ๋‹ค.

ํ•˜์ง€๋งŒ m1์€ zsh๋ฅผ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ํ„ฐ๋ฏธ๋„์„ ์ข…๋ฃŒํ•˜๊ณ  ์‹คํ–‰ํ•˜๋ฉด ๋‹ค์‹œ ์ ์šฉ์‹œ์ผœ์ค˜์•ผํ•˜๋Š” ๋ถˆ์ƒ์‚ฌ๊ฐ€ ์ƒ๊ธด๋‹ค.

๋•Œ๋ฌธ์— .zshrc ํŒŒ์ผ๋„ ์ˆ˜์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

1. vi ~/.zshrc
2. open ~/.zshrc

.zshrc ํŒŒ์ผ์„ ์—ด๊ณ  source ~/.bash_profile์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

์งš๊ณ  ๋„˜์–ด๊ฐ€๋Š” ๋ถ€๋ถ„

๋งฅ๋ถ์€ ํŒŒ์ด์ฌ์„ ๊ธฐ๋ณธ์œผ๋กœ ๋‚ด์žฅํ•˜๊ณ  ์žˆ๋‹ค.

ํ˜น Homebrew๋กœ ์„ค์น˜ํ•œ ํŒŒ์ด์ฌ์ด ๊ธฐ์กด์— ์žˆ๋˜ ํŒŒ์ด์ฌ๊ณผ ์ถฉ๋Œํ•˜์ง€ ์•Š์„๊นŒ ๊ฑฑ์ •์ด ๋˜์–ด ๊ธฐ์กด์— ์žˆ๋˜ ํŒŒ์ด์ฌ์„ ์ œ๊ฑฐํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค.

Python ๊ฒฝ๋กœ

  • Homebrew๋กœ ์„ค์น˜ํ•œ Python: /opt/homebrew/bin/python3
  • ๊ธฐ์กด์— ์žˆ๋˜ Python: /usr/bin/python3

๊ธฐ์กด ๋งฅ๋ถ์˜ Python ๊ฒฝ๋กœ๋Š” /usr/bin/python3

๊ธฐ์กด ๋งฅ๋ถ์˜ Python์ด ์žˆ๋˜ Frameworks ๊ฒฝ๋กœ์—์„œ 3.8 version์˜ python์„ ์‚ญ์ œํ•˜๋‹ˆ /usr/bin/python3, /usr/bin/pip3์˜ ์‹คํ–‰ ๊ฒฝ๋กœ๊ฐ€ Homebrew์˜ python์œผ๋กœ ๋ฐ”๋€Œ์—ˆ์Œ

๐Ÿ’ก Install Miniforge

wget ์„ค์น˜

  • Wget์€ ์›น ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์ฝ˜ํ…์ธ ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋žจ
  • GNU ํ”„๋กœ์ ํŠธ ์ผ๋ถ€
  • Web Get์˜ ์•ฝ์–ด
brew install wget

wget์„ ์ด์šฉํ•œ miniforge ์„ค์น˜

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh

(Next)
bash Miniforge3-MacOSX-arm64.sh

bash ๊ฐ€์ƒํ™˜๊ฒฝ์ด ์ž๋™์œผ๋กœ ์‹คํ–‰๋˜์ง€ ์•Š๊ฒŒ ์„ค์ •

conda config --set auto_activate_base false

๐Ÿ’ก Miniforge ์‚ฌ์šฉํ•ด๋ณด๊ธฐ

miniforge ๊ฐ€์ƒํ™˜๊ฒฝ ๋””ํดํŠธ ๊ฒฝ๋กœ

  • /Users/local/miniforge3/envs

์‹ค์Šต

  • conda create -n <๊ฐ€์ƒํ™˜๊ฒฝ> python=3.9
    • ํŒŒ์ด์ฌ 3.9 ๋ฒ„์ „์œผ๋กœ ์ง€์ •ํ•˜์—ฌ ์„ค์ •ํ•œ ์ด๋ฆ„์˜ ๊ฐ€์ƒํ™˜๊ฒฝ ์ƒ์„ฑ
  • conda env list
    • ๊ฐ€์ƒํ™˜๊ฒฝ ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅ
  • conda activate <๊ฐ€์ƒํ™˜๊ฒฝ>
    • ๊ฐ€์ƒํ™˜๊ฒฝ ํ™œ์„ฑํ™”
  • conda deactivate
    • ๊ฐ€์ƒํ™˜๊ฒฝ ๋น„ํ™œ์„ฑํ™”
  • conda env remove -n <๊ฐ€์ƒํ™˜๊ฒฝ>
    • ๊ฐ€์ƒํ™˜๊ฒฝ ์‚ญ์ œ

๐Ÿ’ก Install Visual Studio Code

Vscode๋„ Homebrew๋ฅผ ์ด์šฉํ•ด ์„ค์น˜

Vscode์—์„œ Python์„ ์ฒ˜์Œ ์‚ฌ์šฉํ•˜๋ฉด Python extension์„ ์„ค์น˜ํ•˜๋ผ๋Š” ์•Œ๋ฆผ์ด ๋œจ๋Š”๋ฐ ์„ค์น˜ํ•˜๋ฉด ๋จ

Python interpreter ์„ ํƒ

  • Command + Shift + P๋กœ ๋ช…๋ น์–ด ํŒ”๋ ˆํŠธ์— ์ง„์ž…ํ•ด Python:Select Interpreter๋ฅผ ์‹คํ–‰ํ•ด Miniforge๋กœ ์ƒ์„ฑํ•œ ๊ฐ€์ƒํ™˜๊ฒฝ์„ ์„ ํƒํ•˜๋ฉด ๋œ๋‹ค.
728x90
๋ฐ˜์‘ํ˜•
Comments