๐Ÿš€ ํŒŒ์ด์ฌ ์˜์กด์„ฑ์„ ๋น ๋ฅด๊ณ  ์‰ฝ๊ฒŒ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•

 

Python ํ”„๋กœ์ ํŠธ์—์„œ ์˜์กด์„ฑ ์ถฉ๋Œ์ด๋‚˜ ์„ค์น˜ ๋ฌธ์ œ๋ฅผ ์‹ ์†ํ•˜๊ฒŒ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ•ด๋ณผ๊ฒŒ์š”.

1๏ธโƒฃ ๊ฐ€์ƒ ํ™˜๊ฒฝ(venv, conda) ์„ค์ • ํ›„ ํŒจํ‚ค์ง€ ์ •๋ฆฌ

 

๐Ÿ’ก ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ๋งŒ๋“ค๊ณ  ๊นจ๋—ํ•œ ์ƒํƒœ์—์„œ ๋‹ค์‹œ ์„ค์น˜

๊ฐ€๋” ๊ธฐ์กด ํ™˜๊ฒฝ์— ์—ฌ๋Ÿฌ ํŒจํ‚ค์ง€๊ฐ€ ์—‰์ผœ์„œ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธธ ์ˆ˜ ์žˆ์–ด์š”. ์ƒˆ ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ๋งŒ๋“ค๊ณ  ํ•„์š”ํ•œ ํŒจํ‚ค์ง€๋งŒ ์„ค์น˜ํ•˜๋ฉด ์˜์กด์„ฑ ์ถฉ๋Œ์„ ์ค„์ผ ์ˆ˜ ์žˆ์–ด์š”.

 

๐Ÿ”น venv ์‚ฌ์šฉ (Python ๊ธฐ๋ณธ ์ œ๊ณต)

python -m venv new_env
source new_env/bin/activate  # Windows๋Š” new_env\Scripts\activate
pip install --upgrade pip
pip install -r requirements.txt

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ƒˆ ํ™˜๊ฒฝ์—์„œ ๊นจ๋—ํ•˜๊ฒŒ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์–ด์š”.

 

๐Ÿ”น Conda ์‚ฌ์šฉ (๋” ๊ฐ•๋ ฅํ•œ ํ™˜๊ฒฝ ๊ด€๋ฆฌ)

conda create -n new_env python=3.10
conda activate new_env
pip install -r requirements.txt

Conda๋Š” ํŒจํ‚ค์ง€ ๊ฐ„ ์˜์กด์„ฑ์„ ๋” ์ž˜ ๊ด€๋ฆฌํ•ด์„œ, ์ถฉ๋Œ์„ ์ค„์ด๋Š”๋ฐ ๋„์›€์ด ๋ผ์š”.

2๏ธโƒฃ pip ์ถฉ๋Œ ํ•ด๊ฒฐ: ํŒจํ‚ค์ง€ ์žฌ์„ค์น˜

 

๐Ÿ’ก ํŒจํ‚ค์ง€๋ฅผ ๊ฐ•์ œ๋กœ ๋‹ค์‹œ ์„ค์น˜ํ•˜์—ฌ ์ถฉ๋Œ ํ•ด๊ฒฐ

pip freeze > installed_packages.txt  # ํ˜„์žฌ ์„ค์น˜๋œ ํŒจํ‚ค์ง€ ๋ฆฌ์ŠคํŠธ ๋ฐฑ์—…
pip uninstall -r installed_packages.txt -y  # ๋ชจ๋“  ํŒจํ‚ค์ง€ ์ œ๊ฑฐ
pip install --upgrade pip setuptools wheel  # ์ตœ์‹  pip ์„ค์น˜
pip install -r requirements.txt  # ์˜์กด์„ฑ ๋‹ค์‹œ ์„ค์น˜

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ธฐ์กด ํ™˜๊ฒฝ์—์„œ ์˜์กด์„ฑ ๋ฌธ์ œ๋ฅผ ํ•œ ๋ฒˆ์— ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์–ด์š”.

3๏ธโƒฃ ํŒจํ‚ค์ง€ ๋ฒ„์ „ ๋ฌธ์ œ ํ•ด๊ฒฐ

 

๐Ÿ’ก ์˜์กด์„ฑ ์ถฉ๋Œ ์‹œ, ๋ฌธ์ œ ํŒจํ‚ค์ง€ ํ™•์ธ ํ›„ ๋ฒ„์ „ ๊ณ ์ •

pip check  # ํ˜„์žฌ ํ™˜๊ฒฝ์—์„œ ์ถฉ๋Œํ•˜๋Š” ํŒจํ‚ค์ง€ ํ™•์ธ
pip install "ํŒจํ‚ค์ง€๋ช…==ํŠน์ •๋ฒ„์ „"  # ํŠน์ • ๋ฒ„์ „์œผ๋กœ ๋งž์ถ”๊ธฐ

์˜ˆ๋ฅผ ๋“ค์–ด, llama-index๊ฐ€ numpy์™€ ์ถฉ๋Œํ•˜๋ฉด:

pip install numpy==1.23.5

์ด๋Ÿฐ ์‹์œผ๋กœ ๋ฒ„์ „์„ ๋งž์ถ”๋ฉด ํ•ด๊ฒฐ๋  ์ˆ˜ ์žˆ์–ด์š”.

4๏ธโƒฃ FastAPI, LangChain, LlamaIndex ๋“ฑ ์ตœ์‹  ํŒจํ‚ค์ง€ ์ถฉ๋Œ ํ•ด๊ฒฐ

 

์ตœ์‹  AI ๊ด€๋ จ ํŒจํ‚ค์ง€(LlamaIndex, LangChain ๋“ฑ)๋Š” ์ข…์ข… ์˜์กด์„ฑ ๋ฌธ์ œ๋ฅผ ์ผ์œผ์ผœ์š”. pip ๋Œ€์‹  pip-compile์„ ์‚ฌ์šฉํ•˜๋ฉด ์˜์กด์„ฑ์„ ์ž๋™์œผ๋กœ ์ •๋ฆฌํ•ด์ค˜์š”.

pip install pip-tools
pip-compile requirements.in  # ์˜์กด์„ฑ ์ž๋™ ์ •๋ฆฌ
pip install -r requirements.txt

5๏ธโƒฃ Docker ํ™œ์šฉ (์ตœํ›„์˜ ๋ฐฉ๋ฒ•)

 

์˜์กด์„ฑ ์ถฉ๋Œ์ด ๋„ˆ๋ฌด ์‹ฌํ•˜๋ฉด Docker๋ฅผ ์‚ฌ์šฉํ•ด ์™„์ „ํ•œ ๊ฒฉ๋ฆฌ๋œ ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•์ด์—์š”.

FROM python:3.10
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD ["python", "your_script.py"]

์ด๋Ÿฐ ์‹์œผ๋กœ ํ•˜๋ฉด, ์‹œ์Šคํ…œ ์˜์กด์„ฑ๊ณผ ๊ด€๊ณ„์—†์ด ๋™์ผํ•œ ํ™˜๊ฒฝ์„ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์–ด์š”.

๐Ÿ“Œ ๊ฒฐ๋ก 

 

โœ… ๋น ๋ฅด๊ฒŒ ํ•ด๊ฒฐํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด?pip check ํ›„ ๋ฒ„์ „ ๋งž์ถ”๊ธฐ

โœ… ๊นจ๋—ํ•œ ํ™˜๊ฒฝ์—์„œ ์žฌ์„ค์น˜?venv ๋˜๋Š” conda ํ™œ์šฉ

โœ… ์ž๋™์œผ๋กœ ์˜์กด์„ฑ์„ ์ •๋ฆฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด?pip-compile ์‚ฌ์šฉ

โœ… 100% ์ถฉ๋Œ ์—†์ด ์‹คํ–‰ํ•˜๋ ค๋ฉด?Docker ์‚ฌ์šฉ

 

๐Ÿš€ venv + pip-compile ์กฐํ•ฉ์„ ๋จผ์ € ์‹œ๋„ํ•˜๊ณ , ๊ทธ๋ž˜๋„ ์•ˆ ๋˜๋ฉด Docker๋ฅผ ๊ณ ๋ คํ•˜๋Š” ๊ฒŒ ๊ฐ€์žฅ ํ˜„์‹ค์ ์ธ ํ•ด๊ฒฐ์ฑ…!

์–ด๋–ค ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š”์ง€ ๋” ๊ตฌ์ฒด์ ์œผ๋กœ ๋งํ•ด์ฃผ๋ฉด, ์ถ”๊ฐ€ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์•Œ๋ ค์ค„ ์ˆ˜ ์žˆ์–ด! ๐Ÿ”ฅ

+ Recent posts