Andrew Fletcher published: 2 October 2023 (updated) 3 October 2023 1 minute read
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 Fletcher
•
17 Mar 2025
Refining text analysis for research data from regex to Python automation
IntroductionData extraction and filtering are crucial for developers working with large research datasets. Whether you're working on government archives, industry reports, or academic research projects, extracting meaningful insights efficiently can be challenging. I'm going to explore how we...
Andrew Fletcher
•
13 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...
Andrew Fletcher
•
07 Dec 2024
Navigating technical infrastructure hiccups when running Python packages in virtual environments
Seemingly minor technical misconfigurations can escalate into major organisational inefficiencies. Consider a scenario where a Python-based web application experiences repeated errors due to missing dependencies, incorrect permissions, and environment mismanagement. Although these challenges appear...