๐Ÿ SETTING ๊ฐœ๋ฐœํ™˜๊ฒฝ ์„ค์ •โ‘  (vscode: python ๊ฐ€์ƒํ™˜๊ฒฝ)

Lightmanยท2022๋…„ 8์›” 9์ผ
4

CS: PYTHON๐Ÿ & โ“‡

๋ชฉ๋ก ๋ณด๊ธฐ
2/14
post-thumbnail

์‚ฌ์šฉํ™˜๊ฒฝ: MacBookPro / macOS Monterey 12.3.1 / VS code
vs code์— conda ๊ฐ€์ƒํ™˜๊ฒฝ์„ ์˜ค๋ฅ˜์—†์ด ์„ค์น˜ํ•ด๋ณด์ž

โ‘  ๊ฐ€์ƒํ™˜๊ฒฝ ์ƒ์„ฑ

  • โžผ ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ฐ€์ƒํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค

    • python 3.10์—์„œ python 3.1๋กœ ์ธ์‹๋˜๋Š” ๋ฒ„๊ทธ๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ 3.9๋ฅผ ์„ค์น˜ํ•˜์ž
      • python=3.1 ๋ฒ„๊ทธ๋Š” ๋งํฌ์˜ issue์—์„œ ํ™•์ธํ•˜์˜€๋‹ค
      • PackageNotFoundError: The following packages are not available from current channels: - python=3.1
    conda create --name [๊ฐ€์ƒํ™˜๊ฒฝ ์ด๋ฆ„] python=3.9
    conda create --name [๊ฐ€์ƒํ™˜๊ฒฝ ์ด๋ฆ„] python=3.10.5 --channel conda-forge
    
    #์ฐธ๊ณ 
    ##conda ๊ฐ€์ƒํ™˜๊ฒฝ ์ด๋ฆ„๋ณ€๊ฒฝ
    conda create --name [new ๊ฐ€์ƒํ™˜๊ฒฝ ์ด๋ฆ„] --clone [old ๊ฐ€์ƒํ™˜๊ฒฝ ์ด๋ฆ„]
    conda activate [๊ฐ€์ƒํ™˜๊ฒฝ ์ด๋ฆ„]
    conda remove --name [์‚ญ์ œํ•  ์ด๋ฆ„] --all
    
    ##conda package ์„ค์ • ๋ฐ ์ดˆ๊ธฐํ™”
    .ymlํŒŒ์ผ ์ด์šฉ(ํ–ฅํ›„ ์—…๋ฐ์ดํŠธ)
    
    ##python package ์„ค์ • ๋ฐ ์ดˆ๊ธฐํ™”
    pip freeze > requirments.txt
    pip install -r requirements.txt
    pip uninstall -r requirements.txt -y
    
    ## conda python version ๋ณ€๊ฒฝ
    conda install python=3.9

๊ฐ€์ƒํ™˜๊ฒฝ ๊ธฐํƒ€ ์„ค์ •

๊ฐ€์ƒํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•˜๊ธฐ๋Š” ํ–ˆ์œผ๋‚˜ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฆฌ๋ˆ…์Šค ์„ธํŒ…์„ ํ™•์ธํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค.

  1. python ๋ช…๋ น์–ด๊ฐ€ ์žˆ๋Š” ์œ„์น˜
  #ํ•ด๋‹น ๊ฐ€์ƒํ™˜๊ฒฝ์ด ์ ‘๊ทผํ•˜๋Š” ๋ช…๋ น์–ด๋“ค์˜ ์œ„์น˜๋Š” $PATH ํ™˜๊ฒฝ๋ณ€์ˆ˜์— ์žˆ์Œ
  $echo $PATH
  #PATH์ค‘์—์„œ python์ด ์œ„์น˜ํ•œ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์•Œ๋ ค์คŒ
  $which -a python
  #๋งŒ์•ฝ conda ํ•˜์œ„์— ์žˆ๋Š” python์ด ์•„๋‹ˆ๋ผ๋ฉด deactivate๊ฐ€ ํ•„์š”ํ•˜๋‹ค
  conda deactivate
  conda activate <๊ฐ€์ƒํ™˜๊ฒฝ ์ด๋ฆ„>
  1. package๋“ค์ด ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์œ„์น˜ ์ฐธ๊ณ 1
  • python -m site
  • conda ๊ฐ€์ƒํ™˜๊ฒฝ์€ ์ž๋™์œผ๋กœ User์˜ global package๋ฅผ ์ฐธ์กฐํ•œ๋‹ค
  #.py์œ„์น˜ ํด๋”, PYTHONPATH๋“ฑ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ์ˆœ์„œ๋Œ€๋กœ ํ‘œํ˜„
  $python -c "import sys; print('/n'.join(sys.path))"
  
  #๋งŒ์•ฝ /Users/****/.local/lib/python3.9/site-packages ์™€ ๊ฐ™์ด global package๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์ง€ ์•Š๋‹ค๋ฉด
  $conda deactivate
  $export PYTHONNOUSERSITE=1
  $conda activate <๊ฐ€์ƒํ™˜๊ฒฝ ์ด๋ฆ„>

์™„๋ฃŒ

  • โžผ ์ด์ œ vscode์—์„œ ํ„ฐ๋ฏธ๋„์„ ์—ด์–ด ๊ฐ€์ƒํ™˜๊ฒฝ์„ ์‹คํ–‰ํ•˜์ž

์ฐธ๊ณ ์‚ฌํ•ญ

  • conda-forge๋Š” ๋‹ค์šด๋กœ๋“œ ์ฑ„๋„์ด๋‹ค [์ฐธ๊ณ ]

์˜๋ฌธ์‚ฌํ•ญ

  • ์ฐธ๊ณ ์ž๋ฃŒ1, 2, 3
  • ํ˜„์žฌ ๋ฒ„์ „์˜ conda ๊ฐ€์ƒํ™˜๊ฒฝ์€ global package์— ์ ‘๊ทผํ•˜๋Š”๊ฐ€ ?
    • PATH์— ๊ธฐ๋ก๋œ ๊ฒƒ์€ ๋ช…๋ น์–ด์ธ๊ฐ€? ์ „๋ถ€ ๋ช…๋ น์–ด์ž„
    • package๋Š” ์–ด๋–ป๊ฒŒ ๊ฒ€์ƒ‰ํ•˜๋Š”๊ฐ€?
  • conda ๊ฐ€์ƒํ™˜๊ฒฝ์ด ์ ‘๊ทผํ•˜๋Š” ํด๋”๋Š” ์–ด๋””์ธ๊ฐ€ ? (ํด๋”๋ช…๋“ค์˜ ์˜๋ฏธ๋Š”?)
    • ์ ‘๊ทผํ•˜๋Š” ํด๋”๊ฐ€ ๋ฐ”๋€Œ๋ฉด shell script๋ฅผ ์‹คํ–‰ํ• ๋•Œ ์ฃผ๋Š” ๊ฐ’๋“ค๋„ ๋ฐ”๋€Œ์–ด์•ผ ํ•˜๋Š”๊ฐ€?
  • conda ๊ฐ€์ƒํ™˜๊ฒฝ์„ ๋ณต์ œํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ•˜๋Š”๊ฐ€ ?
  • global package๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ•˜๋Š”๊ฐ€ ?

๋.

profile
ํ˜„์ง ๋ฐ์ดํ„ฐ ๋ถ„์„๊ฐ€ / ๋ฐ์ดํ„ฐ ๊ณผํ•™์˜ ์ •๋„๋ฅผ ๋”ฐ๋ผ ๐Ÿšฒ / About DEV DA ML

0๊ฐœ์˜ ๋Œ“๊ธ€