Manmohan_singh
Manmohan_singh

Reputation: 1804

import UserDict ModuleNotFoundError: No module named 'UserDict' when running a Flask app with PyJadeExtension

I am upgrading my flask app from python 3.8 to 3.10 as python 3.8 is not going to reach its end of life by October 2024. While running the app.py file. My code throws an exception at this line.

app = Flask(__name__)
app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension') # <-- this line is bugged

#app.register_blueprint(log_routes, url_prefix="/logs")

The exception stacktrace:

Traceback (most recent call last):
  File "/usr/local/anaconda3/envs/py10/lib/python3.10/site-packages/pyjade/runtime.py", line 8, in <module>
    from collections import Mapping as MappingType
ImportError: cannot import name 'Mapping' from 'collections' (/usr/local/anaconda3/envs/py10/lib/python3.10/collections/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/manmohansinghvirdi/GitHub/qa-cp-simulator/CPStationSimulator/qawebserver/qawebserver.py", line 27, in <module>
    app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')
  File "/usr/local/anaconda3/envs/py10/lib/python3.10/site-packages/jinja2/environment.py", line 375, in add_extension
    self.extensions.update(load_extensions(self, [extension]))
  File "/usr/local/anaconda3/envs/py10/lib/python3.10/site-packages/jinja2/environment.py", line 119, in load_extensions
    extension = t.cast(t.Type["Extension"], import_string(extension))
  File "/usr/local/anaconda3/envs/py10/lib/python3.10/site-packages/jinja2/utils.py", line 149, in import_string
    return getattr(__import__(module, None, None, [obj]), obj)
  File "/usr/local/anaconda3/envs/py10/lib/python3.10/site-packages/pyjade/__init__.py", line 4, in <module>
    from .utils import process
  File "/usr/local/anaconda3/envs/py10/lib/python3.10/site-packages/pyjade/utils.py", line 224, in <module>
    from .ext.html import Compiler as HTMLCompiler
  File "/usr/local/anaconda3/envs/py10/lib/python3.10/site-packages/pyjade/ext/html.py", line 6, in <module>
    from pyjade.runtime import is_mapping, iteration, escape
  File "/usr/local/anaconda3/envs/py10/lib/python3.10/site-packages/pyjade/runtime.py", line 10, in <module>
    import UserDict
ModuleNotFoundError: No module named 'UserDict'

After searching a lot on online forums, I found that I should update from collections import MutableMapping to from collections.abc import MutableMapping , as mentioned here - https://github.com/Significant-Gravitas/AutoGPT/issues/65#issuecomment-1494259607

However, this is going to update the core packages and not make it a seamless solution for CI/CD pipelines. Is there a solution to this exception stacktrace ?

Upvotes: 0

Views: 571

Answers (0)

Related Questions