본문 바로가기
ERROR

dotenv 설치 시 AttributeError, has no attribute 'read_dotenv'

by 코드뭉치 2023. 4. 25.

1. AttributeError : module 'setuptools' has no attribute '_install_setup_requires'

dotenv 설치 명령어 입력시 에러 발생

더보기
$ poetry add dotenv

Using version ^0.0.5 for dotenv

Updating dependencies
Resolving dependencies...

Package operations: 1 install, 0 updates, 0 removals

  • Installing dotenv (0.0.5)

  ChefBuildError

  Backend subprocess exited when trying to invoke build_wheel

  Traceback (most recent call last):
             
                     ...
             
      setuptools._install_setup_requires
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  AttributeError: module 'setuptools' has no attribute '_install_setup_requires'


  at ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\installation\chef.py:152 in _prepare
      148│
      149│                 error = ChefBuildError("\n\n".join(message_parts))
      150│
      151│             if error is not None:
    → 152│                 raise error from None
      153│
      154│             return path
      155│
      156│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry 
but with dotenv (0.0.5) not supporting PEP 517 builds. You can verify this by running 
'pip wheel --use-pep517 "dotenv (==0.0.5)"'

 

 대충 읽어보니 poetry사용과 관련한 문제는 아니라고 한다. 실제로 pip install을 진행해도 설치되지 않았다.

마지막에 적혀있는 'pip wheel --use-pep517 "dotenv (==0.0.5)"' 로 설치해도 오류가 발생.

 

알아보니 dotenv는 node.js용이고, 파이썬 또는 장고에서 dotenv를 사용하려면

각각 python-dotenv, django-dotenv를 설치해야 한다.

 pip install python-dotenv
 	 # 또는
 pip install django-dotenv

 

 

그래도 문제가 발생한다면, setuptools의 버전이 맞지 않아서 문제가 발생했을 수 있다.

위의 에러와 비슷한 에러들은 거의 pip의 버전문제일 확률이 높다.

pip install --upgrade setuptools
python -m pip install --upgrade pip

 


2. AttributeError: module 'dotenv' has no attribute 'read_dotenv'

django-dotenv 공식 깃허브

 

python-dotenv, django-dotenv, dotenv 중 여러개를 설치 시 문제가 발생할 수 있다.

 

모든 dotenv를 지우고, 필요한 dotenv를 설치해봐도 해결되지 않는다면,

다른 환경 변수 관리 방법을 사용해보는 것이 좋다. 다른 환경 변수 관리 방법으로는 decouple, secrets.json등이 있다.

다른 환경 변수 관리방법

댓글