반응형
Python Poetry: Python 패키지 관리 도구
Python 프로젝트에서 의존성 및 패키지 관리는 매우 중요하다. Poetry는 이를 효율적으로 처리할 수 있도록 설계된 Python 패키지 관리 도구이다.
Poetry 개요
- pyproject.toml 기반 설정
- 의존성 자동 관리
- 가상환경 생성 및 격리
- 패키지 빌드 및 배포 지원
- PEP 517, PEP 518 호환
설치 방법
curl -sSL https://install.python-poetry.org | python3 -
설치 확인:
poetry --version
macOS/Linux에서는 위 명령어 그대로 사용 가능하며, Windows에서는 PowerShell에서 실행한다.
Poetry 기본 사용법
1. 새 프로젝트 생성
poetry new 프로젝트명
2. 기존 프로젝트에 Poetry 초기화
poetry init
poetry init -n # 기본값으로 생성
3. 패키지 설치
poetry add requests
poetry add --dev black
4. 패키지 제거
poetry remove 패키지명
5. 가상환경 진입
poetry shell
6. 명령어 실행
poetry run python main.py
7. 의존성 설치 및 업데이트
poetry install
poetry update
Poetry 주요 명령어 요약
명령어 | 설명 |
---|---|
poetry new 프로젝트명 | 새로운 프로젝트 생성 |
poetry init | 기존 프로젝트 초기화 |
poetry add 패키지명 | 패키지 설치 |
poetry add --dev 패키지명 | 개발용 의존성 설치 |
poetry remove 패키지명 | 패키지 제거 |
poetry install | pyproject.toml 기반 의존성 설치 |
poetry update | 패키지 업데이트 |
poetry shell | 가상환경 진입 |
poetry run 명령어 | 가상환경에서 명령어 실행 |
poetry build | 패키지 빌드 |
poetry publish | PyPI 배포 |
Poetry 도입 시 장점
- 가상환경 자동 생성 및 분리
- 의존성 정의 및 잠금 기능 (lock file)
- 직관적인 프로젝트 구조 구성
- 배포를 위한 빌드 및 publish 기능 통합
728x90
반응형