Skip to main content

Python3

Error

ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/home/{project}/.local/lib/python3.8/site-packages/markupsafe/__init__.py)

 

Update all PIP packages

pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U

However, this failed due to 

AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

 

To resolve the X509_V_FLAG_CB_ISSUER_CHECK error, run

sudo pip3 install pyOpenSSL --upgrade
sudo pip3 install cryptography --upgrade

 

Back on track

The "ImportError: cannot import name 'soft_unicode' from 'markupsafe'" occurs as a result of soft_unicode method has been deprecated in markupsafe version 2.1.0.  Now to check the current version that's in use of key packages

Package                 Version
----------------------- --------------------
Jinja2                  2.10.1
MarkupSafe              2.1.3
pip                     20.0.2

 

Checking jinja2

The minimum versions of this package are expected by Jinja2:

# for pinned (obsolete) Jinja2: `MarkupSafe` has been automatically downgraded  by `pip` to `2.0.1`
MarkupSafe==2.0.1
 - Jinja2==2.11.3 [requires: MarkupSafe>=0.23]

# whereas unpinned:

# for unpinned (latest) Jinja2: using latest version of `MarkupSafe`
MarkupSafe==2.1.1
 - Jinja2==3.1.2 [requires: MarkupSafe>=2.0]

 

Downgrading MarkupSafe

Downgrading markupsafe module to 2.0.1 version

pip install markupsafe==2.0.1
pip3 install markupsafe==2.0.1

Response

Collecting markupsafe==2.0.1
  Downloading MarkupSafe-2.0.1-cp38-cp38-manylinux2010_x86_64.whl (30 kB)
Installing collected packages: markupsafe
  Attempting uninstall: markupsafe
    Found existing installation: MarkupSafe 2.1.3
    Uninstalling MarkupSafe-2.1.3:
      Successfully uninstalled MarkupSafe-2.1.3
Successfully installed markupsafe-2.0.1

Confirming that the current version of markupsafe has been downgraded

Package                 Version
----------------------- --------------------
Jinja2                  2.10.1
MarkupSafe              2.0.1
pip                     20.0.2

 

 

Related articles

Andrew Fletcher13 Feb 2025
Deploying a Python project from UAT to production using Git
When deploying a Python project from a User Acceptance Testing (UAT) environment to Production, it’s essential to ensure that all dependencies and configurations remain consistent. Particularly in our situation where this was going to be the first deployment of AI semantic search functionality to...