Search code examples
pythonquart

Python Quart import error : cannot import name 'soft_unicode' from 'markupsafe'


I am installing the Quart module for Python on a newly upgraded server - to Debian 11:

name -a
Linux 9D895EB 5.10.0-19-amd64 #1 SMP Debian 5.10.149-2 (2022-10-21) x86_64 GNU/Linux

When I try running Quart I get the following:

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.9/runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/usr/local/lib/python3.9/dist-packages/quart/__init__.py", line 5, in <module>
    from .app import Quart as Quart
  File "/usr/local/lib/python3.9/dist-packages/quart/app.py", line 50, in <module>
    from .asgi import ASGIHTTPConnection, ASGILifespan, ASGIWebsocketConnection
  File "/usr/local/lib/python3.9/dist-packages/quart/asgi.py", line 29, in <module>
    from .debug import traceback_response
  File "/usr/local/lib/python3.9/dist-packages/quart/debug.py", line 6, in <module>
    from jinja2 import Template
  File "/usr/lib/python3/dist-packages/jinja2/__init__.py", line 12, in <module>
    from .environment import Environment
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 25, in <module>
    from .defaults import BLOCK_END_STRING
  File "/usr/lib/python3/dist-packages/jinja2/defaults.py", line 3, in <module>
    from .filters import FILTERS as DEFAULT_FILTERS  # noqa: F401
  File "/usr/lib/python3/dist-packages/jinja2/filters.py", line 13, in <module>
    from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/usr/local/lib/python3.9/dist-packages/markupsafe/__init__.py)

When I installed quart on my previous dev box or laptop I didn't get this issue. I have seen comments about installing a previous version of a library, but, nothing related to quart as such.

Here is a list of installed module versions:

Jinja2             3.1.2
MarkupSafe         2.1.1
quart              0.18.3
requests           2.25.1
Werkzeug           2.2.2

Update: With the update to MarkupSafe 2.1.1 and the others I now get:

File "/usr/local/lib/python3.9/dist-packages/quart/cli.py", line 506, in _load_plugin_commands
for point in entry_points(group="quart.commands"):
TypeError: entry_points() got an unexpected keyword argument 'group'

Solution

  • The MarkupSafe package is not 2.0.1

    $ pip install markupsafe==2.0.1
    $ pip list --no-index --format=json | jq -r '.[] | select(.name=="MarkupSafe").version'
    2.0.1
    
    >>> from markupsafe import soft_unicode
    >>> 
    
    
    $ pip install markupsafe==2.1.0
    $ pip list --no-index --format=json | jq -r '.[] | select(.name=="MarkupSafe").version'
    2.1.0
    
    >>> from markupsafe import soft_unicode
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/home/cetver/.local/lib/python3.10/site-packages/markupsafe/__init__.py)
    

    UPD:

    Update https://github.com/python/importlib_metadata

    or

    Update Python to 3.10 https://github.com/pallets/quart/blob/0.18.3/src/quart/cli.py#L498