poetry shell은 해당 프로젝트의 가상환경을 활성화하는 명령어이다.
그러나 poetry 버전이 2.0으로 업데이트 되면서
해당 명령어가 삭제되었다.
갑자기 없어진 명령어가 불편하게 느껴져 해결방법을 찾던 중,
shell 명령어를 다시 사용할 수 있는 plug-in 설치 방법을 찾았다.
poetry self add poetry-plugin-shell
poetry에 추가패키지를 설치하는 self명령어로 간단하게 plug-in을 설치할 수 있다.
해당 플러그인을 설치한 후 poetry shell 명령어를 실행하면,
프로젝트/.venv/bin 경로에 있는 activate 파일을 실행하여 가상환경을 활성화한다.
가상환경 활성화하는 과정이 궁금해서 살펴본 activate 파일의 스크립트는 아래와 같다.
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
if [ "${BASH_SOURCE-}" = "$0" ]; then
echo "You must source this script: \$ source $0" >&2
exit 33
fi
deactivate () {
unset -f pydoc >/dev/null 2>&1 || true
# reset old environment variables
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
if ! [ -z "${_OLD_VIRTUAL_PATH:+_}" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi
# The hash command must be called to get it to forget past
# commands. Without forgetting past commands the $PATH changes
# we made may not be respected
hash -r 2>/dev/null
if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
PS1="$_OLD_VIRTUAL_PS1"
export PS1
unset _OLD_VIRTUAL_PS1
fi
unset VIRTUAL_ENV
unset VIRTUAL_ENV_PROMPT
if [ ! "${1-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
# unset irrelevant variables
deactivate nondestructive
VIRTUAL_ENV=/home/cybot_RAG/.venv
if ([ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ]) && $(command -v cygpath &> /dev/null) ; then
VIRTUAL_ENV=$(cygpath -u "$VIRTUAL_ENV")
fi
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/"bin":$PATH"
export PATH
if [ "x"cybot-rag-py3.11 != x ] ; then
VIRTUAL_ENV_PROMPT=cybot-rag-py3.11
else
VIRTUAL_ENV_PROMPT=$(basename "$VIRTUAL_ENV")
fi
export VIRTUAL_ENV_PROMPT
# unset PYTHONHOME if set
if ! [ -z "${PYTHONHOME+_}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
unset PYTHONHOME
fi
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1-}"
PS1="(${VIRTUAL_ENV_PROMPT}) ${PS1-}"
export PS1
fi
# Make sure to unalias pydoc if it's already there
alias pydoc 2>/dev/null >/dev/null && unalias pydoc || true
pydoc () {
python -m pydoc "$@"
}
# The hash command must be called to get it to forget past
# commands. Without forgetting past commands the $PATH changes
# we made may not be respected
hash -r 2>/dev/null || true
1. 기존 가상환경을 정리
2. 새로운 가상환경을 활성화
3. 쉘 프롬프트 표시 변경
스크립트 주요 내용은 위와 같은 것을 확인할 수 있었다.
참고:
https://github.com/python-poetry/poetry/issues/9962
The command "shell" does not exist. on Poetry 2.0.0 · Issue #9962 · python-poetry/poetry
Description While running poetry shell in any of my repositories I am getting The command "shell" does not exist.. poetry run is working fine, which is even more confusing. Workarounds Downgrading ...
github.com
'Language > Python' 카테고리의 다른 글
[Python] 깊은 복사(deepcopy) (0) | 2025.02.12 |
---|