Rasa init RuntimeError: dictionary changed size during iteration

I have issues like this after Rasa init Traceback (most recent call last): File “/usr/local/bin/rasa”, line 8, in sys.exit(main()) File “/Library/Python/3.7/site-packages/rasa/main.py”, line 82, in main set_log_level(log_level) File “/Library/Python/3.7/site-packages/rasa/utils/common.py”, line 71, in set_log_level update_tensorflow_log_level() File “/Library/Python/3.7/site-packages/rasa/utils/common.py”, line 107, in update_tensorflow_log_level import tensorflow as tf File “/Library/Python/3.7/site-packages/tensorflow/init.py”, line 101, in from tensorflow_core import * File “/Library/Python/3.7/site-packages/tensorflow_core/init.py”, line 40, in from tensorflow.python.tools import module_util as _module_util File “”, line 983, in _find_and_load File “”, line 959, in _find_and_load_unlocked File “/Library/Python/3.7/site-packages/tensorflow/init.py”, line 50, in getattr module = self._load() File “/Library/Python/3.7/site-packages/tensorflow/init.py”, line 44, in _load module = _importlib.import_module(self.name) File “/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/init.py”, line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File “/Library/Python/3.7/site-packages/tensorflow_core/python/init.py”, line 64, in from tensorflow.core.framework.graph_pb2 import * File “/Library/Python/3.7/site-packages/tensorflow_core/core/framework/graph_pb2.py”, line 7, in from google.protobuf import descriptor as _descriptor File “/Library/Python/3.7/site-packages/google/protobuf/init.py”, line 37, in import(‘pkg_resources’).declare_namespace(name) File “/Library/Python/3.7/site-packages/pkg_resources/init.py”, line 84, in import(‘pkg_resources.extern.packaging.requirements’) File “/Library/Python/3.7/site-packages/pkg_resources/_vendor/packaging/requirements.py”, line 9, in from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException File “”, line 983, in _find_and_load File “”, line 967, in _find_and_load_unlocked File “”, line 668, in _load_unlocked File “”, line 638, in _load_backward_compatible File “/Library/Python/3.7/site-packages/pkg_resources/extern/init.py”, line 43, in load_module import(extant) File “/Library/Python/3.7/site-packages/pkg_resources/_vendor/pyparsing.py”, line 4756, in _escapedPunc = Word( _bslash, r"[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1]) File “/Library/Python/3.7/site-packages/pkg_resources/_vendor/pyparsing.py”, line 1284, in setParseAction self.parseAction = list(map(_trim_arity, list(fns))) File “/Library/Python/3.7/site-packages/pkg_resources/_vendor/pyparsing.py”, line 1066, in _trim_arity this_line = extract_stack(limit=2)[-1] File “/Library/Python/3.7/site-packages/pkg_resources/_vendor/pyparsing.py”, line 1050, in extract_stack frame_summary = traceback.extract_stack(limit=-offset+limit-1)[offset] File “/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py”, line 211, in extract_stack stack = StackSummary.extract(walk_stack(f), limit=limit) File “/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py”, line 363, in extract f.line File “/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py”, line 285, in line self._line = linecache.getline(self.filename, self.lineno).strip() File “/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py”, line 16, in getline lines = getlines(filename, module_globals) File “/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py”, line 48, in getlines for mod in sys.modules.values(): RuntimeError: dictionary changed size during iteration

Python version: pip3 --version pip 20.0.2 from /Library/Python/3.7/site-packages/pip (python 3.7)

Any idea what’s happening here?

I have the exactly the same error. All I did was run the following lines and got the same error:

python3 -m venv ./venv
source ./venv/bin/activate
pip3 install -U pip
pip3 install rasa
rasa init

I checked the version of the installed rasa, and confirmed it’s 1.8.0

Did anyone have this issue and was able to resolve?

The vendored version of pyparsing that is being used is very old, most likely due to having an old version of packaging and/or setuptools. Please update both using pip3 install -U setuptools or pip3 install -U packaging. Unfortunately, since these are vendored copies of pyparsing, you cannot fix this problem by updating pyparsing (latest released version is 2.4.6, and this code dates back to at least 2.2.1).

It seems to me that there is more to this, I made sure I have updated packaging and setuptools and still get the same RuntimeError: dictionary changed size during iteration error on rasa train inside the examples/formbot folder that is.

  1. Set up new fresh virtual env in the examples/formbot
  2. installed the updated pip3 and packaging and setuptools
  3. installed rasa still same error

For reference, here is a reconstruction of the traceback from the original post, properly formatted for better readability:

File "/usr/local/bin/rasa", line 8, in 
    sys.exit(main())
File "/Library/Python/3.7/site-packages/rasa/main.py", line 82, in main 
    set_log_level(log_level) 
File "/Library/Python/3.7/site-packages/rasa/utils/common.py", line 71, in set_log_level 
    update_tensorflow_log_level() 
File "/Library/Python/3.7/site-packages/rasa/utils/common.py", line 107, in update_tensorflow_log_level 
    import tensorflow as tf 
File "/Library/Python/3.7/site-packages/tensorflow/init.py", line 101, in 
    from tensorflow_core import * 
File "/Library/Python/3.7/site-packages/tensorflow_core/init.py", line 40, in 
    from tensorflow.python.tools import module_util as _module_util 
File "", line 983, in 
    _find_and_load 
File "", line 959, in 
    _find_and_load_unlocked 
File "/Library/Python/3.7/site-packages/tensorflow/init.py", line 50, in getattr 
    module = self._load()
File "/Library/Python/3.7/site-packages/tensorflow/init.py", line 44, in _load 
    module = _importlib.import_module(self.name)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/init.py", line 127, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level)
File "/Library/Python/3.7/site-packages/tensorflow_core/python/init.py", line 64, in 
    from tensorflow.core.framework.graph_pb2 import * 
File "/Library/Python/3.7/site-packages/tensorflow_core/core/framework/graph_pb2.py", line 7, in 
    from google.protobuf import descriptor as _descriptor
File "/Library/Python/3.7/site-packages/google/protobuf/init.py", line 37, in 
    import('pkg_resources').declare_namespace(name)
File "/Library/Python/3.7/site-packages/pkg_resources/init.py", line 84, in 
    import('pkg_resources.extern.packaging.requirements')
File "/Library/Python/3.7/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in 
    from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
File "", line 983, in 
    _find_and_load
File "", line 967, in 
    _find_and_load_unlocked
File "", line 668, in 
    _load_unlocked
File "", line 638, in 
    _load_backward_compatible
File "/Library/Python/3.7/site-packages/pkg_resources/extern/init.py", line 43, in load_module 
    import(extant)
File "/Library/Python/3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 4756, in 
    _escapedPunc = Word( _bslash, r"[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
File "/Library/Python/3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1284, in setParseAction 
    self.parseAction = list(map(_trim_arity, list(fns)))
File "/Library/Python/3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1066, in 
    _trim_arity this_line = extract_stack(limit=2)[-1]
File "/Library/Python/3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1050, in extract_stack 
    frame_summary = traceback.extract_stack(limit=-offset+limit-1)[offset]
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py", line 211, in extract_stack 
    stack = StackSummary.extract(walk_stack(f), limit=limit)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py", line 363, in extract 
    f.line
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py", line 285, in line 
    self._line = linecache.getline(self.filename, self.lineno).strip()
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py", line 16, in getline 
    lines = getlines(filename, module_globals)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py", line 48, in getlines 
    for mod in sys.modules.values(): 
RuntimeError: dictionary changed size during iteration

I thought that the version of pyparsing was the problem, but I just checked my own Python3.6 and Python 3.8 installations, and they too have the same 2.2.1 version of pyparsing. :frowning:

If you are absolutely desperate, you can try extracting the pyparsing.py file from the pyparsing GitHub repo (pyparsing/pyparsing.py at pyparsing_2.4.x · pyparsing/pyparsing · GitHub) and replacing the one in your pkg_resources/_vendor directory. This version has been tested on Python 2.7 thru 3.8. If that still doesn’t work, then one of the other related packages will need to be reviewed.

@here facing the same issue. any fix???

I have the same issue! Anyone has a fix to it?

It seems to be an issue related to tensorflow, potentially also to macOS. Based on the issue found here.

I may have found a fix. I am running on macOS and when I switch my python version to 3.6.8 then it seems to work again. It is also suggested here that upgrading to 3.7.5 might also offer a solution.

same problem here, RuntimeError produced by rasa init. Any fix to this yet?

(venv) lhim0036:~ mittelsh$ rasa init Traceback (most recent call last): File “/Users/mittelsh/venv/bin/rasa”, line 8, in sys.exit(main()) File “/Users/mittelsh/venv/lib/python3.7/site-packages/rasa/main.py”, line 82, in main set_log_level(log_level) File “/Users/mittelsh/venv/lib/python3.7/site-packages/rasa/utils/common.py”, line 71, in set_log_level update_tensorflow_log_level() File “/Users/mittelsh/venv/lib/python3.7/site-packages/rasa/utils/common.py”, line 112, in update_tensorflow_log_level import tensorflow as tf File “/Users/mittelsh/venv/lib/python3.7/site-packages/tensorflow/init.py”, line 101, in from tensorflow_core import * File “/Users/mittelsh/venv/lib/python3.7/site-packages/tensorflow_core/init.py”, line 40, in from tensorflow.python.tools import module_util as _module_util File “”, line 983, in _find_and_load File “”, line 959, in _find_and_load_unlocked File “/Users/mittelsh/venv/lib/python3.7/site-packages/tensorflow/init.py”, line 50, in getattr module = self._load() File “/Users/mittelsh/venv/lib/python3.7/site-packages/tensorflow/init.py”, line 44, in _load module = _importlib.import_module(self.name) File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/init.py”, line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File “/Users/mittelsh/venv/lib/python3.7/site-packages/tensorflow_core/python/init.py”, line 64, in from tensorflow.core.framework.graph_pb2 import * File “/Users/mittelsh/venv/lib/python3.7/site-packages/tensorflow_core/core/framework/graph_pb2.py”, line 7, in from google.protobuf import descriptor as _descriptor File “/Users/mittelsh/venv/lib/python3.7/site-packages/google/protobuf/init.py”, line 37, in import(‘pkg_resources’).declare_namespace(name) File “/Users/mittelsh/venv/lib/python3.7/site-packages/pkg_resources/init.py”, line 83, in import(‘pkg_resources.extern.packaging.requirements’) File “/Users/mittelsh/venv/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/requirements.py”, line 9, in from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException File “”, line 983, in _find_and_load File “”, line 967, in _find_and_load_unlocked File “”, line 668, in _load_unlocked File “”, line 638, in _load_backward_compatible File “/Users/mittelsh/venv/lib/python3.7/site-packages/pkg_resources/extern/init.py”, line 43, in load_module import(extant) File “/Users/mittelsh/venv/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py”, line 4756, in _escapedPunc = Word( _bslash, r"[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1]) File “/Users/mittelsh/venv/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py”, line 1284, in setParseAction self.parseAction = list(map(_trim_arity, list(fns))) File “/Users/mittelsh/venv/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py”, line 1066, in _trim_arity this_line = extract_stack(limit=2)[-1] File “/Users/mittelsh/venv/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py”, line 1050, in extract_stack frame_summary = traceback.extract_stack(limit=-offset+limit-1)[offset] File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py”, line 211, in extract_stack stack = StackSummary.extract(walk_stack(f), limit=limit) File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py”, line 363, in extract f.line File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py”, line 285, in line self._line = linecache.getline(self.filename, self.lineno).strip() File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py”, line 16, in getline lines = getlines(filename, module_globals) File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py”, line 48, in getlines for mod in sys.modules.values(): RuntimeError: dictionary changed size during iteration