재테크 A2Z

2025.05.19 Poetry로 Python 프로젝트 설정하는 방법 (윈도우 기준) 본문

코딩 & 파이썬

2025.05.19 Poetry로 Python 프로젝트 설정하는 방법 (윈도우 기준)

a2ztec 2025. 5. 19. 19:16

🐍 Poetry로 Python 프로젝트 설정하는 방법 (윈도우 기준)

이 글에서는 Python + Poetry + VS Code 환경에서 패키지 관리 및 프로젝트 구조화를 어떻게 효율적으로 할 수 있는지 정리합니다.
개발 자동화, 의존성 관리, 가상환경 설정을 일관성 있게 유지하고 싶은 분들께 추천합니다.


📦 Poetry란?

Poetry는 Python 프로젝트의 패키지 관리 및 빌드 도구입니다.
pip + venv + requirements.txt의 번거로움을 하나로 통합해주는 도구입니다.


✅ 1. Poetry 설치 (Windows)

▶ PowerShell 열고 다음 명령어 실행

powershell
복사편집
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

▶ 환경변수 경로 추가 (안 될 경우 수동 등록)

Poetry 실행파일이 설치되는 경로:

css
복사편집
C:\Users\{사용자이름}\AppData\Roaming\Python\Scripts

이를 환경 변수 PATH에 추가해 줍니다.

▶ 설치 확인

powershell
복사편집
poetry --version

✅ 출력 예시:

scss
복사편집
Poetry (version 2.1.3)

✅ 2. 프로젝트 생성

아래 명령어로 새로운 프로젝트를 생성합니다:

bash
복사편집
poetry new 프로젝트이름

예:

bash
복사편집
poetry new autobot-trader

생성 결과 구조:

markdown
복사편집
autobot-trader/ ├── pyproject.toml ├── README.rst ├── autobot_trader/ │ └── __init__.py └── tests/ └── __init__.py

✅ 3. Python 버전 명시 (예: 3.10)

pyproject.toml 파일의 [project] 블록에 추가:

toml
복사편집
requires-python = ">=3.10"

또는 명령어로 Python 버전 지정:

bash
복사편집
poetry env use C:\Users\yourname\AppData\Local\Programs\Python\Python310\python.exe

✅ 4. 의존성 패키지 설치

예: Pandas, Numpy, matplotlib, ccxt, pyupbit, schedule 등

bash
복사편집
poetry add pandas numpy matplotlib ccxt pyupbit schedule

✅ 5. 가상환경 활성화

Poetry 2.0+에서는 poetry shell이 빠졌으므로 다음 명령어로 진입:

bash
복사편집
poetry env info --path

출력 경로의 Scripts\Activate.ps1를 PowerShell에서 실행:

powershell
복사편집
& "C:\Users\you\AppData\Local\pypoetry\Cache\virtualenvs\프로젝트명-xxx\Scripts\Activate.ps1"

✅ 6. VS Code 연동

▶ Python 인터프리터 선택

  1. Ctrl + Shift + P → "Python: Select Interpreter"
  2. 위에서 확인한 가상환경의 python.exe 경로 선택

VS Code가 .vscode/settings.json 자동 생성


✅ 7. pyproject.toml 구성 예시

toml
복사편집
[project] name = "autobot-trader" version = "0.1.0" requires-python = ">=3.10" dependencies = [ "pandas>=2.2.3,<3.0.0", "numpy>=2.2.6,<3.0.0", "matplotlib>=3.10.3,<4.0.0", "pyupbit>=0.2.34,<0.3.0", "ccxt>=4.4.82,<5.0.0", "schedule>=1.2.2,<2.0.0" ] [tool.poetry] packages = [{ include = "autobot_trader", from = "src" }]

🎯 마무리

이제부터 poetry install, poetry add, poetry update 등으로
의존성 관리를 쉽고 명확하게 할 수 있습니다.
또한 pyproject.toml 하나로 모든 프로젝트 설정을 추적할 수 있어 협업에도 최적화되어 있습니다.