AttributeError: module 'collections' has no attribute 'Mapping'
Python Python 3.10.9 Jupyter Notebook 6.5.2
!pip install experta
Requirement already satisfied: experta in c:\programdata\anaconda3\lib\site-packages (1.9.4)
Requirement already satisfied: frozendict==1.2 in c:\programdata\anaconda3\lib\site-packages (from experta) (1.2)
Requirement already satisfied: schema==0.6.7 in c:\programdata\anaconda3\lib\site-packages (from experta) (0.6.7)
from experta import *
AttributeError Traceback (most recent call last) Cell In[9], line 1 ----> 1 from experta import *
File C:\ProgramData\anaconda3\lib\site-packages\experta_init_.py:5 3 try: 4 from .conditionalelement import AND, OR, NOT, TEST, EXISTS, FORALL ----> 5 from .engine import KnowledgeEngine 6 from .fact import Fact, InitialFact, Field 7 from .fieldconstraint import L, W, P
File C:\ProgramData\anaconda3\lib\site-packages\experta\engine.py:13 10 from experta import abstract 12 from experta.agenda import Agenda ---> 13 from experta.fact import InitialFact 14 from experta.factlist import FactList 15 from experta.rule import Rule
File C:\ProgramData\anaconda3\lib\site-packages\experta\fact.py:9 6 from schema import Schema 8 from experta.pattern import Bindable ----> 9 from experta.utils import freeze, unfreeze 10 from experta.conditionalelement import OperableCE 11 from experta.conditionalelement import ConditionalElement
File C:\ProgramData\anaconda3\lib\site-packages\experta\utils.py:4 1 from functools import singledispatch 2 import collections.abc ----> 4 from frozendict import frozendict 6 from .fieldconstraint import P 9 class frozenlist(tuple):
File C:\ProgramData\anaconda3\lib\site-packages\frozendict_init_.py:16
10 OrderedDict = NotImplemented
13 iteritems = getattr(dict, 'iteritems', dict.items) # py2-3 compatibility
---> 16 class frozendict(collections.Mapping):
17 """
18 An immutable wrapper around dictionaries that implements the complete :py:class:collections.Mapping
19 interface. It can be used as a drop-in replacement for dictionaries where immutability is desired.
20 """
22 dict_cls = dict
AttributeError: module 'collections' has no attribute 'Mapping'
After deleting the site-packages
!pip install experta
Collecting experta
Using cached experta-1.9.4-py3-none-any.whl (35 kB)
Requirement already satisfied: frozendict==1.2 in c:\programdata\anaconda3\lib\site-packages (from experta) (1.2)
Requirement already satisfied: schema==0.6.7 in c:\programdata\anaconda3\lib\site-packages (from experta) (0.6.7)
Installing collected packages: experta
Successfully installed experta-1.9.4
from experta import *
...
AttributeError: module 'collections' has no attribute 'Mapping'
This is a problem with python 3.10 upwards. If you create a conda environment with python 3.9 it works in ubuntu.
This is a problem with python 3.10 upwards. If you create a conda environment with python 3.9 it works in ubuntu.
Any other fix for this? I tested with 3.9.18 on python venv and I got the same error
Using
This is a problem with python 3.10 upwards. If you create a conda environment with python 3.9 it works in ubuntu.
Any other fix for this? I tested with 3.9.18 on python venv and I got the same error
Installing python 3.8.18 worked for me
Tested in Python 3.12.3.
It looks like collections.Mapping was moved to collections.abc.Mapping. The file frozendict/__init__.py has to be changed to correct this. The class is defined like this:
class frozendict(collections.Mapping)
Change to
class frozendict(collections.abc.Mapping)