You have landed on this post because you facing or have faced this “importerror: cannot import name ‘soft_unicode’ from ‘markupsafe’“. The cause of this error is as a result of incompatibility of markupsafe packages.
MarkupSafe creates a text object that escapes characters in order to make texts objects safe to use in HTML and XML.
Without wasting much time, let us look at the various ways we can solve the error importerror: cannot import name ‘soft_unicode’ from ‘markupsafe‘ error.
Method 1: Upgrading MarkupSafe Module
If you are using an older version of MarkupSafe, then it will be advisable to update to the latest version. Enter the command below to upgrade MarkupSafe to the latest version.
pip install MarkupSafe
If the above method didn’t work, try the next method.
Method 2: Downgrading MarkupSafe Module
In some cases, you may need to downgrade your MarkupSafe module for it to work. During our tests and research, the version that seems to work most of the time is version 2.0.1. Use the command below to downgrade your MarkupSafe module. You can change the version number to your preferred stable version number.
pip install markupsafe==2.0.1
If the above method also does not work for you, you can try the next one.
Method 3 – Upgrade the aws-sam-cli module
AWS-SAM-CLI gives you a command line tool that makes it easy to create serverless applications. If you are using an outdated version, you can easily upgrade by using the command below.
pip install --user --upgrade aws-sam-cli
Method 4 – Downgrade the aws-sam-cli module
Other people face this importerror: cannot import name ‘soft_unicode’ from ‘markupsafe’ with the latest version of aws-sam-cli module. You can consider downgrading this to a lower version which worked in most cases. The suggest you try version 1.37.0. Use the command below to downgrade your aws-sam-cli to version 1.37.0.
pip install --user aws-sam-cli ==1.37.0
Now you have know how to solve importerror: cannot import name ‘soft_unicode’ from ‘markupsafe’, if you are still have a challenge, you can try with markupsafe version 2.0.1 and aws-sam-cli version 1.37.0.
Also if you have been able to solve it successfully, use the comment box to tell us which method worked for you.