brew install poetry
brew install python@3.xx
brew info python@3.12
로 경로 확인
poetry env use {파이썬 경로}
인터프리터 지정
brew install python@3.9
-> Python has been installed as
/opt/homebrew/bin/python3.9
pyenv로 파이썬 특정 버전 설치하기.
pyenv install -l로 가능한 버전 확인
egrep으로 특정 버전 확인
pyenv install -l | egrep "^\s+3.11"
pyenv install 3.11.6
pyenv local 3.11.6
python -m venv venv
source venv/bin/activate
pyenv versions로 가상환경 확인
poetry 설치
curl -sSL https://install.python-poetry.org | python3 -
Install on MacOs fails with Exception: This build of python cannot create venvs without using symlinks
curl로 설치 안되면 brew install poetry
pyproject.toml이 있는 디렉토리에서 실행
poetry shell
또는
source /{home}/Library/Caches/pypoetry/virtualenvs/...-py3.9/bin/activate
또는
특정 파이썬 버전으로 가상환경을 만들고 싶다면
파이썬 경로 : brew info python@3.12
로 확인
poetry env use {파이썬 경로}
The specified Python version (3.9.18) is not supported by the project (3.9.2).
Please choose a compatible version or loosen the python constraint specified in the pyproject.toml file.
toml 파일에 정확한 python 버전 명시해야 함
poetry init
값을 지정하면 pyproject.toml 파일 생성됨.
python 버전 지정하면 그에 맞는 가상환경이 생성됨.
poetry shell을 치면 가상환경 활성화되고 경로가 나옴. 이 경로를 IDE 에 적용하면 됨
vscode에 .vscode/settings.json 설정
"python.defaultInterpreterPath": "/Users/simon/Library/Caches/pypoetry/virtualenvs/everycharge-backend-dXiQi3sf-py3.9/bin/python",
또는 cmd + shift + p로 select interpreter 설정 켜고 가상환경 지정
Existing environment에서 ...
클릭
생성한 경로에서 python 선택
버전 확인 후 OK
poetry add {패키지명}
pyproject.toml 로부터 프로젝트 의존성 설치. lock파일 있으면 이거대로 설치하고 없으면 설치 후 lock 파일 생성함
poetry install
lock 파일 활용해서 설치
poetry.lock에 있는 버전대로 설치함
poetry lock
설치 없이 pyproject.toml 에 명시된 의존성을 lock함
poetry export --without-hashes -f requirements.txt --output requirements.txt
lock file을 다른 형식으로 추출함. -f로 requirements.txt
포맷 지정, --output으로 출력 파일 지정
requirements.txt 기반 poetry install
cat requirements.txt | xargs poetry add
or poetry add $( cat requirements.txt )
poetry 설치된 package list 조회
poetry show
현 프로젝트와 관련있는 poetry 가상환경 리스트
poetry env list
현재 실행중인 가상환경 정보
poetry env info
가상환경 삭제
poetry env remove /full/path/to/python
https://pypi.org/ 가입,
credential 설정하기
poetry config http-basic.foo <username> <password>
배포 전 빌드(패키징)하기. 배포 프로세스, 설치, 사용을 간편하게 만드는 작업.
poetry build
패키지가 Python Package Index (PyPI)에 배포됨
poetry publish
poetry.lock 없이 install하기
install 명령을 하지 않았거나 poetry.lock 파일이 존재하지 않을 때 poetry는 pyproject.toml 파일에 있는 의존성들을 해결하고 파일의 최신 버전을 다운로드한다.
설치가 완료되면 poetry.lock 파일에다가 다운로드된 모든 패키지와 정확한 버전을 작성하고 패키지들의 특정 버전으로 락킹한다. poetry.lock 파일도 반드시 커밋해야 개발자들이 같은 의존성의 패키지를 설치할 수 있다
poetry.lock으로 install하기
pyproject.toml 에 있는 의존성들을 해결하고 설치하지만 poetry.lock에 있는 정확한 버전을 사용해서 프로젝트에 속한 개발자들이 일관된 패키지 버전을 사용할 수 있게 한다.
pyproject.toml 파일?
설치하려는 패키지를 명시.
poetry.lock 파일?
이름, 버전, 설명 등 작성하는 섹션들이 존재함.
명시된 패키지 버전만 설치하도록 함.