소프트웨어

[pyjwt] AttributeError: module 'jwt' has no attribute 'encode' 에러 해결

TaeGyeong Lee 2023. 7. 26. 16:30

문제 상황

pyjwt를 설치하여 jwt encode 함수를 사용하려 하였으나 아래와 같은 에러가 발생하였습니다.

Traceback (most recent call last):
File "< stdin >", line 1, in
AttribureError: module 'jwt' has no attribure 'encode'

 

해결 방법

jwt 라이브러리 삭제 후 pyjwt 라이브러리를 설치하였음에도 발생할 수 있는 문제입니다. uninstall 명령을 통해 jwt 라이브러리를 삭제 시도하였음에도 jwt 라이브러리 디렉토리 파일이 삭제되지 않아 발생할 수 있는 문제입니다.

파이썬 라이브러리 설치 경로를 확인합니다. 임의의 설치된 라이브러릴 하나를 골라 설치 경로를 확인해 주세요.

pip3 show requests
Name: requests
Version: 2.31.0
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: /Users/taegyeonglee/Library/Python/3.9/lib/python/site-packages
Requires: certifi, charset-normalizer, idna, urllib3
Required-by: jupyterlab_server

제 파이썬 라이브러리 설치 경로는 /Users/taegyeonglee/Library/Python/3.9/lib/python/site-packages 입니다.

 

파이썬 라이브러리 설치 경로로 이동합니다.

cd /Users/taegyeonglee/Library/Python/3.9/lib/python/site-packages

 

jwt 라이브러리 디렉토리 파일을 완전히 삭제합니다.

rm -rf jwt

 

이후 사용중인 IDE를 재시작, pyjwt 를 삭제, 설치해 보세요. 정상적으로 사용가능합니다.

 

출처

 

AttributeError: module 'jwt' has no attribute 'encode' · Issue #374 · jpadilla/pyjwt

Using import jwt encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256') Traceback (most recent call last): File "< stdin >", line 1, in AttribureError: module 'jwt' has no attribure...

github.com