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 Fletcher29 Feb 2024
Python - OSError: [Errno 24] Too many open files
The "Too many open files" error in Python typically occurs when your program has opened more file descriptors than the operating system allows. This error is often seen in situations where files are not being properly closed after use, leading to the exhaustion of available file...
Andrew Fletcher17 Feb 2024
How to update installed Python packages
You can use the pip list --outdated command to view a list of installed Python packages that have newer versions available. This command will show you which packages are outdated and can be updated to the latest versions.Here's how you can use itpip list --outdatedThis command will display a list of...