syrusakbary / pyjade

Jade template system for Django, Jinja2 and Mako
MIT License
698 stars 124 forks source link

Not compatible with Python 3.10 (cannot import name 'Mapping' from 'collections') #293

Open wolfgang42 opened 2 years ago

wolfgang42 commented 2 years ago

This was apparently a deprecated alias which was removed in Python 3.10; the new way of doing it is collections.abc.

Traceback (most recent call last):
  File "/usr/local/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/lib/python3.10/collections/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  [...]
  File "/usr/local/lib/python3.10/site-packages/pyjade/runtime.py", line 10, in <module>
    import UserDict
ModuleNotFoundError: No module named 'UserDict'

Workaround: use Python 3.9 instead.

Ucag commented 2 years ago

您好,我是李冬,您发来的邮件已收到,我将会尽快回复您

fatsen commented 3 months ago

Open the folder of pyjade, and open runtime.py, then change from collections import Mapping as MappingType into from collections.abc import Mapping as MappingType. This problem solved, and it works ok for python 3.11.8. I don't know the reason, for i got this solution from my python teacher.

wolfgang42 commented 2 months ago

@fatsen Your (teacher’s) change works because Mapping was moved from collections to collections.abc in Python 3.3.

However, do note that editing the source code of a library in the files that were installed is generally considered a bad idea: it will work on your computer, but is confusing when you come back to the program later when you have forgotten you did that, and is hard to keep track of if you ever give the program to someone else.