pyjwt: AttributeError: module 'jwt' has no attribute 'encode'
Using
import jwt
encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
Traceback (most recent call last):
File “< stdin >”, line 1, in <module>
AttribureError: module ‘jwt’ has no attribure ‘encode’
Same issue with using decode
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 26 (1 by maintainers)
use “pip install pyjwt”
Do you have a file called jwt.py in the same directory where you are trying to run the code?
You might have installed another package jwt
Did you run
pip install jwt
? @heroh9Uninstalling “jwt” then installing “pyjwt” worked for me.
pip3 install pyjwt==1.5.3
did the magic
Had a similar issue. Accidentally installed jwt first. Just removing jwt and installing PyJWT did not help. Recreating my virtual environment and installing PyJWT fixed the issue.
uninstall all of them then “pip install pyjwt”
For anyone installed
jwt
directly and the Python environment cannot be easily reset: Try this:The problem is at the
site-packages/jwt
folder. After runspip uninstall jwt
, the folder still exists. You have to remove it manually. And then, thePyJWT
folder is still stuck insite-packages
. You have to reinstall it in order to move it to the defaultjwt
folder.This solved my issue. Thanks!
I had named my script “token.py” and that caused this error
It works, thanks. because of incopatibility
djangorestframework-jwt 1.11.0 requires PyJWT<2.0.0,>=1.5.2, but you have pyjwt 2.3.0 which is incompatible
I had the same problem (but with ‘decode’). The fix was as @vungsung said, but you can fix PyJWT in one step with:
thanks