개요

처음 python 을 접하고 놀랬던 것은 패키지 매니저인 pip 의 부실한 설계와 구현으로 인한 다음과 불편함이었습니다.

  1. name space 가 없음
  2. 기본적으로 global 로 패키지를 설치(–user 옵션 필요)
  3. 유의적 버전을 미지원
  4. lock 파일이 없어서 프로젝트 참여자간 의존성 일치가 어려움

심지어 이런 부분은 자주 비난받는 언어인 PHP의 패키지 관리자인 composer 에서도 이미 오래전부터 잘 지원하는 기능이라 굉장히 의외였습니다.


poetry는 이런 문제를 개선하기 위한 새로운 파이썬 패키지 관리자로써  

사용

설치

poetry 는 python 2.7 또는 3.5+ 를 지원하며 pip 로는 설치할 수 없고 별도의 설치 방법을 제공하고 있습니다.


bash 를 사용할수 있는 Linux(WSL 포함) 나 MacOS 는 curl 을 사용하면 됩니다.

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

설치후에는 poetry 를 실행할 수 있도록 다음 경로를 쉘 초기화 파일에 추가해 줍니다.

export PATH=$PATH:$HOME/.poetry/bin
BASH


Windows 라면 powershell 을 열고 다음 명령을 실행하면 됩니다.

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -
POWERSHELL

Windows 에서도 다음 경로를 PATH 환경 변수에 추가해 주면 됩니다.

%USERPROFILE%\.poetry\bin
POWERSHELL


옵션

poetry 를 옵션없이 실행하면 사용 방법을 표시합니다.

$ poetry 

Poetry version 1.1.11

USAGE
  poetry [-h] [-q] [-v [<...>]] [-V] [--ansi] [--no-ansi] [-n] <command> [<arg1>] ... [<argN>]

AVAILABLE COMMANDS
  about                  Shows information about Poetry.
  add                    Adds a new dependency to pyproject.toml.
  build                  Builds a package, as a tarball and a wheel by default.
  cache                  Interact with Poetry's cache
  check                  Checks the validity of the pyproject.toml file.
  config                 Manages configuration settings.
  debug                  Debug various elements of Poetry.
  env                    Interact with Poetry's project environments.
BASH


특정 명령어의 자세한 사용법을 보려면 help 뒤에 명령어를 입력합니다.

poetry help add
BASH

또는 명령어 뒤에 --help 옵션을 주고 실행해도 됩니다.

poetry add --help
BASH


의존성 기술 파일

poetry 는 의존성 기술 파일로 yaml 이 아닌 toml 형식을 사용하며 패키지 설정 파일명은 pyproject.toml 입니다.

pyproject.toml 을 생성하려면  init 명령을 실행합니다.

poetry init
BASH


add -  의존성 추가

새로운 패키지를 추가하려면 add 명령뒤에 패키지 

poetry add numpy

Using version ^1.21.2 for numpy

Updating dependencies
Resolving dependencies...

Writing lock file

Package operations: 1 install, 0 updates, 0 removals

  • Installing numpy (1.21.2)
BASH


같이 보기

Ref