๐Ÿ SETTING ๊ฐ€์ƒํ™˜๊ฒฝ CONDA ์„ค์ •๊ณผ ๋ฌธ์ œ ํ•ด๊ฒฐ

Lightmanยท2021๋…„ 7์›” 19์ผ
1

CS: PYTHON๐Ÿ & โ“‡

๋ชฉ๋ก ๋ณด๊ธฐ
11/14

๐Ÿคด conda/pip ๊ฐ€์ƒํ™˜๊ฒฝ

  • ์‚ฌ์šฉํ™˜๊ฒฝ: Windows, git bash, Anaconda

ํŒŒ์ด์ฌ์œผ๋กœ ๋‹ค์–‘ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•˜๋‹ค ๋ณด๋ฉด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๊ฐ€์ƒํ™˜๊ฒฝ์˜ ์ƒ์„ฑ์ด ํ•„์ˆ˜์ ์ด๋‹ค.
๊ฐ€์ƒํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  pip install์„ ์ˆ˜ํ–‰ํ•˜๋ฉด ํŒŒ์ด์ฌ ์„ค์น˜ํด๋”/Lib/site-packages์— ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์ด ๋ฌดํ„ฑ๋Œ€๊ณ  ์Œ“์—ฌ ํ˜ธํ™˜์„ฑ ๋ฌธ์ œ๋ฅผ ์ผ์œผํ‚ค๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

์šฐ๋ฆฌ๋Š” ํ™˜๊ฒฝ์„ ์ชผ๊ฐœ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฐ€์ƒํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค. ์„ฑ์žฅํ•ด๊ฐ€๋Š” ์ž๋…€์—๊ฒŒ ๋…๋ฆฝ๋œ ๊ณต๊ฐ„์„ ๋งˆ๋ จํ•ด์ค˜์•ผ ๊ฑด๊ฐ•ํ•˜๊ฒŒ ์ž๋ž„ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋‹ค.

ํฌ๊ฒŒ pip๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ conda๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃจ๋Š” ๋งŽ์€ ์ด๋“ค์ด Anaconda๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋ฏ€๋กœ ํ•ด๋‹น ๋ฐฉ๋ฒ•์œผ๋กœ ์„ค๋ช…ํ•˜๋ ค๊ณ  ํ•œ๋‹ค.

๐Ÿ›ซ๊ฐ€์ƒํ™˜๊ฒฝ ์ƒ์„ฑ ๋ฐ ํ™œ์„ฑํ™”

1. ๊ฐ€์ƒํ™˜๊ฒฝ ์ƒ์„ฑ

conda create --name ๊ฐ€์ƒํ™˜๊ฒฝ ํด๋”๋ช…
conda create --name ex_env

์•„๋‚˜์ฝ˜๋‹ค ์„ค์น˜ํด๋”:Anaconda3/Scripts/conda๋ช…๋ น์–ด์ธ conda create๋กœ ๊ฐ€์ƒํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•˜๋ฉด ์•„๋‚˜์ฝ˜๋‹ค ์„ค์น˜ํด๋”:Anaconda3/envs/๊ฐ€์ƒํ™˜๊ฒฝ์ด๋ฆ„์œผ๋กœ ์ผ์ข…์˜ ํด๋”์ฒ˜๋Ÿผ ๊ฐ€์ƒํ™˜๊ฒฝ์ด ์ƒ์„ฑ๋œ๋‹ค.

2. ํ™˜๊ฒฝ์„ค์ •(์ค‘์š”)

 source ~/anaconda3/etc/profile.d/conda.sh

git bash๋ฅผ ์ด์šฉํ•˜๊ณ  ์žˆ๋‹ค๋ฉด ์œ„ ์„ค์ •์„ ์‹คํ–‰ํ•ด์ค˜์•ผ๋งŒ ๊ฐ€์ƒํ™˜๊ฒฝ์ด ํ™œ์„ฑํ™”๋œ๋‹ค.

  • ๋‹ค์Œ์ด ๋„์›€๋˜๋Š” ๊ฒƒ์„ ๋ฐœ๊ฒฌํ•˜์˜€๋‹ค.
conda init bash

3. ํ™œ์„ฑํ™” ๋ฐ ๋น„ํ™œ์„ฑํ™”

 conda activate ๊ฐ€์ƒํ™˜๊ฒฝ ํด๋”๋ช… / conda deactivate
 conda activate ex_env
 conda deactivate

์ด์ œ ๊ฐ€์ƒํ™˜๊ฒฝ์—์„œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•˜๊ณ  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค.

4. ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜ ๋ฐ ์‚ฌ์šฉ

โ‘  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

conda install numpy=1.11.3=py36_0

conda install์„ ์ด์šฉํ•ด์•ผ ๊ฐ€์ƒํ™˜๊ฒฝ ํด๋”/Lib/site-packages์— ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๋…๋ฆฝ์ ์œผ๋กœ ์„ค์น˜๋œ๋‹ค. pip3 install์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ์•„๋‚˜์ฝ˜๋‹ค ์„ค์น˜ํด๋”:Anaconda3/Lib/site-packages์•ˆ์— ์„ค์น˜๋œ๋‹ค. (๋ฒ„์ „์ด ๋ณ€๊ฒฝ๋˜๋ฉด์„œ pip3๊ฐ€ ์•„๋‹Œ pip install์€ conda install๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํ–‰๋™ํ•˜๊ฒŒ ๋œ ๊ฒƒ ๊ฐ™๋‹ค.) ๋”ฐ๋ผ์„œ ๋…๋ฆฝ์ ์ธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ณต๊ฐ„์„ ๊ตฌ์„ฑํ•˜๋ ค๋ฉด conda install์„ ์‚ฌ์šฉํ•˜์ž.

โ‘ก ํŒจํ‚ค์ง€ ๋ชฉ๋ก ๊ด€๋ฆฌํ•˜๊ธฐ

pip freeze > requirements.txt		# ํ˜„์žฌ ๊ฐ€์ƒํ™˜๊ฒฝ์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ €์žฅํ•œ๋‹ค.
pip install -r requirements.txt		# ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ผ๊ด„ ์„ค์น˜ํ•œ๋‹ค.
pip uninstall -r requirements.txt	# ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ผ๊ด„ ์ œ๊ฑฐํ•œ๋‹ค.

freeze ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ํ™˜๊ฒฝ์„ ์‰ฝ๊ฒŒ ์˜ฎ๊ธธ ์ˆ˜ ์žˆ๋‹ค.

to be continued

๐Ÿ˜Ž๋.

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

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