You have landed on this post because you facing or have faced this “importerror: cannot import name ‘json’ from ‘itsdangerous’“. The cause of this error is a result of incompatibility of flask and itsdangerous package versions.
Now you may ask what is itsdangerous package and what is it used for. Itsdangerous package is a python package that allows helpers to pass data to untrusted sources without it being tempered and returns the data safe and sound.
Method 1: Upgrading Flask
Since this problem is mostly caused by your current Flask version not being compatible with the itsdangerous package version. Our first recommended solution is to upgrade Flask to the latest version by using the command below.
pip install flask
You may face importerror: cannot import name ‘soft_unicode’ from ‘markupsafe’. If that happens update MarkupSafe to its recent version by using the command below.
pip install markupsafe
If the problem still exists then let’s move to the next method.
Method 2: Downgrading itsdangerous Package
Flask 1.1.2 package is set up in a way that requires or compatible itsdangerous versions 0.24 and above.
So if you are having Flask 1.1.2, then you may try downgrading your itsdangerous version to 2.0.1, not 2.10. To install Flask 1.1.2 and itsdangerous to 2.0.1, use the commands below
pip install flask==1.1.2
pip install itsdangerous==2.0.1
Best Compatibility options
If you have tried all of the above but still the problem still exists, then I will suggest the following alternatives.
- Upgrade all packages to the latest versions: You can also try upgrading all the three packages; flask, itsdangerous, and markupsafe to their latest version. Use the commands below.
pip install flask
pip install itsdannnngerous
pip install markupsafe
- Alternative 2: You can also maintain these packages versions which worked for most people. Flask at version 1.1.4 and itsdangerous at version 2.0.1. Use the commands below.
pip install flask=1.1.4
pip install itsdangerous=1.1.0
Conclusion
Now, you have known how to solve importerror: cannot import name ‘json’ from ‘itsdangerous’, if you still have a challenge, you can use the comment box to tell us which method worked for you.