티스토리 뷰

Development/Python

Poetry 사용방법

juniz 2021. 12. 13. 01:19
반응형

Poetry

기술을 사용하기 전에 우선 왜 사용하는 지 알고 넘어 가야 합니다.

poetry는 의존성 관리 및 python 내 패키징을 위한 툴로 pip과 유사한 위치를 갖고 있습니다.

 

pip의 경우 대부분 requirements.txt 파일을 만들어서 관리를 했으며

pipenv 의 경우 lock파일을 통해 관리를 하게 되는데

poetry의 경우 *.toml 로 관리를 합니다. 

 

poetry는 가상환경 여부를 확인해서 관리가 가능하기 때문에 virtualenv 등과 굳이 사용을 안해도 됩니다.

pip 보다 편하게 의존성 관리를 해주는 패키지라고 생각하시면 됩니다. 

 

설치 방법

# Install 
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

# ~/.zshrc
vim ~/.zshrc
export PATH="$HOME/.poetry/bin:$PATH"

 

간단 명령어

# Create project
poetry new <Project name> 

# In project
poetry init

# Add package
poetry add django

# Add package with specific version
poetry add "django>=3.2,<3.3" 


# Install dependencies
poetry install 

## Without dependency
poetry install --no-dev


# Update
poetry update

# Remove package
poetry remove <package name>

# Show
poetry show

poetry show --tree

# Build
poetry build

# Publish
poetry publish # Need PyPI account

# Export
poetry export -f <filename> > <filename>


# Error check
poetry check

# Config
poetry config

 

가상환경 관련

# Use
poetry env use {python dir}

# Check
poetry env info

 

필수라고 생각되지는 않지만 최근에 자주 글에서 보여 

간단한 사용법은 알고 있으면 좋지 않을까 싶어 정리해본 글입니다.

pip의 최신화 버전으로 알고 있으면 이해하기 좋지 않을까 생각합니다. 

npm : yarn = pip : poetry

 

추후에 config 관련되서 추가할 예정입니다. 

 

공식 document: https://python-poetry.org/docs/

 

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/02   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
글 보관함
반응형