[Python] PyCharm에 Poetry 설정 시 poetry ModuleNotFoundError: No module named ‘chardet’ 에러 해결

[Python] PyCharm에 Poetry 설정 시 poetry ModuleNotFoundError: No module named ‘chardet’ 에러 해결

파이참(PyCharm)에서 Python Interpreter로 Poetry 추가 시 아래와 같은 에러가 발생했다.

poetry ModuleNotFoundError: No module named ‘chardet’

설치된 파이썬 버전은 3.10이고 Poetry 설치된 상태였다. PyCharm IDE에서 Interpreter 추가 시 위 에러 메세지와 함께 크래쉬 창이 출력되었고 원인을 분석했다.

원인은 로컬에 설치된 Poetry의 venv 상에 chardet 라이브러리가 설치되지 않은 것이었고 설치되지 않은 라이브러리 참조에 의한 에러였다.

우선 로컬에 설치된 Poetry 경로를 아래 커맨드로 찾아보자.

# poetry 설치 경로 확인
$ which poetry
>> /Users/{User}/.local/bin/poetry

# 물리 경로 확인
$ cd /Users/{User}/.local/bin
$ ls
>> poetry -> /Users/{User}/Library/Application Support/pypoetry/venv/bin/poetry

# Application Support 사이에 Escape(\)를 추가해서 경로에 접근해야한다.
$ source /Users/{User}/Library/Application\ Support/pypoetry/venv/bin/activate

# venv를 활성화 한 뒤 chardet 라이브러리를 설치한다.
(venv)$ pip3 install chardet

위와 같이 성공적으로 설치 후 Poetry Interpreter 경로를 아래와 같이 지정해주면 성공적으로 설정이 완료된다.

/Users/{User}/Library/Application Support/pypoetry/venv/bin/poetry

%d 블로거가 이것을 좋아합니다: