tensorflow: RuntimeError: dictionary changed size during iteration
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Mac OS 10.15 Beta (virtual environment)
- TensorFlow installed from (source or binary): source
- TensorFlow version: 2.0.0
- Python version: 3.7.3
- Installed using virtualenv? pip? conda?: virtualenv pip
Describe the problem I run into this issue where I can’t test the most basic Tensorflow program cause it gives me this error at the end: RuntimeError: dictionary changed size during iteration
I was trying to work on a virtual environment I had already setup but it wasn’t working either and it kept giving me that error. So I created a new one from cero and it keeps giving me the error. The tensorflow is properly installed (according to the instructions) but when I try to run the simple program to test it. It gives me the error. I’ll add to the log the error and the log of when the Tensorflow is being installed. I hope this is not an unique issue.
Provide the exact sequence of commands / steps that you executed before running into the problem
➜ ML python3 -m venv env
➜ ML source env/bin/activate
(env) ➜ ML pip install --upgrade pip
(env) ➜ ML pip install tensorflow
(env) ➜ ML python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
_and here I get the error._
Any other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.
**(env) ➜ ML pipip install tensorflow**
Collecting tensorflow
Using cached https://files.pythonhosted.org/packages/2c/72/6b3264aa2889b7dde7663464b99587d95cd6a5f3b9b30181f14d78a63e64/tensorflow-2.0.0-cp37-cp37m-macosx_10_11_x86_64.whl
Collecting wrapt>=1.11.1 (from tensorflow)
Collecting keras-preprocessing>=1.0.5 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/28/6a/8c1f62c37212d9fc441a7e26736df51ce6f0e38455816445471f10da4f0a/Keras_Preprocessing-1.1.0-py2.py3-none-any.whl
Collecting gast==0.2.2 (from tensorflow)
Collecting keras-applications>=1.0.8 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/71/e3/19762fdfc62877ae9102edf6342d71b28fbfd9dea3d2f96a882ce099b03f/Keras_Applications-1.0.8-py3-none-any.whl
Collecting tensorboard<2.1.0,>=2.0.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/9b/a6/e8ffa4e2ddb216449d34cfcb825ebb38206bee5c4553d69e7bc8bc2c5d64/tensorboard-2.0.0-py3-none-any.whl
Collecting tensorflow-estimator<2.1.0,>=2.0.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/95/00/5e6cdf86190a70d7382d320b2b04e4ff0f8191a37d90a422a2f8ff0705bb/tensorflow_estimator-2.0.0-py2.py3-none-any.whl
Collecting numpy<2.0,>=1.16.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/b4/e8/5ececadd9cc220bb783b4ce6ffaa9266925d37ed41237bc23bc530ab4f3d/numpy-1.17.2-cp37-cp37m-macosx_10_6_intel.whl
Collecting termcolor>=1.1.0 (from tensorflow)
Collecting google-pasta>=0.1.6 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/d0/33/376510eb8d6246f3c30545f416b2263eee461e40940c2a4413c711bdf62d/google_pasta-0.1.7-py3-none-any.whl
Collecting grpcio>=1.8.6 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/75/07/f1d41d10519ca165b0e078949078f20beb57e7e46dc0f1d56b73bb01270a/grpcio-1.24.1-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting opt-einsum>=2.3.2 (from tensorflow)
Collecting wheel>=0.26 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl
Collecting six>=1.10.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting absl-py>=0.7.0 (from tensorflow)
Collecting protobuf>=3.6.1 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/a5/c6/a8b6a74ab1e165f0aaa673a46f5c895af8780976880c98934ae82060356d/protobuf-3.10.0-cp37-cp37m-macosx_10_9_intel.whl
Collecting astor>=0.6.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/d1/4f/950dfae467b384fc96bc6469de25d832534f6b4441033c39f914efd13418/astor-0.8.0-py2.py3-none-any.whl
Collecting h5py (from keras-applications>=1.0.8->tensorflow)
Using cached https://files.pythonhosted.org/packages/1a/8b/4d01ae9a9d50a0bcc7b0b9aae41785d8d9de6fa9bba04dc20b1582181d2d/h5py-2.10.0-cp37-cp37m-macosx_10_6_intel.whl
Collecting werkzeug>=0.11.15 (from tensorboard<2.1.0,>=2.0.0->tensorflow)
Using cached https://files.pythonhosted.org/packages/ce/42/3aeda98f96e85fd26180534d36570e4d18108d62ae36f87694b476b83d6f/Werkzeug-0.16.0-py2.py3-none-any.whl
Collecting markdown>=2.6.8 (from tensorboard<2.1.0,>=2.0.0->tensorflow)
Using cached https://files.pythonhosted.org/packages/c0/4e/fd492e91abdc2d2fcb70ef453064d980688762079397f779758e055f6575/Markdown-3.1.1-py2.py3-none-any.whl
Collecting setuptools>=41.0.0 (from tensorboard<2.1.0,>=2.0.0->tensorflow)
Using cached https://files.pythonhosted.org/packages/6a/9a/50fadfd53ec909e4399b67c74cc7f4e883488035cfcdb90b685758fa8b34/setuptools-41.4.0-py2.py3-none-any.whl
Installing collected packages: wrapt, six, numpy, keras-preprocessing, gast, h5py, keras-applications, grpcio, wheel, werkzeug, setuptools, markdown, protobuf, absl-py, tensorboard, tensorflow-estimator, termcolor, google-pasta, opt-einsum, astor, tensorflow
Found existing installation: setuptools 40.8.0
Uninstalling setuptools-40.8.0:
Successfully uninstalled setuptools-40.8.0
Successfully installed absl-py-0.8.1 astor-0.8.0 gast-0.2.2 google-pasta-0.1.7 grpcio-1.24.1 h5py-2.10.0 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.1.1 numpy-1.17.2 opt-einsum-3.1.0 protobuf-3.10.0 setuptools-41.4.0 six-1.12.0 tensorboard-2.0.0 tensorflow-2.0.0 tensorflow-estimator-2.0.0 termcolor-1.1.0 werkzeug-0.16.0 wheel-0.33.6 wrapt-1.11.2
**(env) ➜ ML pypython -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"**
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/tensorflow/__init__.py", line 98, in <module>
from tensorflow_core import *
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/tensorflow_core/__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 959, in _find_and_load_unlocked
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/tensorflow/__init__.py", line 50, in __getattr__
module = self._load()
File "/Users/marialopez/projects/ML/env/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/marialopez/projects/ML/env/lib/python3.7/site-packages/tensorflow_core/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/tensorflow_core/core/framework/graph_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/google/protobuf/__init__.py", line 37, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/pkg_resources/__init__.py", line 84, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/pkg_resources/extern/__init__.py", line 43, in load_module
__import__(extant)
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 4756, in <module>
_escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1284, in setParseAction
self.parseAction = list(map(_trim_arity, list(fns)))
File "/Users/marialopez/projects/ML/env/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1066, in _trim_arity
this_line = extract_stack(limit=2)[-1]
File "/Users/marialopez/projects/ML/env/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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 33 (1 by maintainers)
By replacing the line in linecache.py I have gotten past this:
For python 3.7.3 (native) on Catalina the following works (add
list()to make a copy):Note in ln 48: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py
I am experiencing this same issue as well. I am using MacOS Catalina. Steps to reproduce this:
I get the following error:
Please let me know if you need more information
I compared native and virtual environments … they look very similar … BUT … the successful machine is using Clang 10.0.1 whereas the other one is using 11.0.0
details:
Catalina - Successful installation (Native)
$ python
WARNING: Python 2.7 is not recommended. This version is included in macOS for compatibility with legacy software. Future versions of macOS will not include Python 2.7. Instead, it is recommended that you transition to using ‘python3’ from within Terminal.
Python 2.7.16 (default, Aug 24 2019, 18:37:03) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin
$ python3 Python 3.7.3 (default, Jun 19 2019, 07:38:49) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.
Catalina - Successful installation (Virtual Env)
source venv/bin/activate (venv) $ python Python 3.7.3 (default, Jun 19 2019, 07:38:49) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin
(venv) $ python3 Python 3.7.3 (default, Jun 19 2019, 07:38:49) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin
>>>importtensorflow>>>tensorflow.__version__‘2.0.0’Catalina - Non Successful installation (Native)
$ python WARNING: Python 2.7 is not recommended. This version is included in macOS for compatibility with legacy software. Future versions of macOS will not include Python 2.7. Instead, it is recommended that you transition to using ‘python3’ from within Terminal.
Python 2.7.16 (default, Aug 24 2019, 18:37:03) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin
$ python3 Python 3.7.3 (default, Sep 18 2019, 14:29:06) [Clang 11.0.0 (clang-1100.0.33.8)] on darwin
Catalina - Non Successful installation (Virtual Env)
(venv) $ python Python 3.7.3 (default, Sep 18 2019, 14:29:06) [Clang 11.0.0 (clang-1100.0.33.8)] on darwin
(venv) $ python3 Python 3.7.3 (default, Sep 18 2019, 14:29:06) [Clang 11.0.0 (clang-1100.0.33.8)] on darwin
I have the same problem on Catalina 10.15.2 with Python 3.7.3 Python 3.7.3 (default, Nov 15 2019, 04:04:52) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.
Just clean install tensorflow.
Below solved this problem by modify the line 48 of “linecache.py” file.
for mod in list(sys.modules.values()): # for mod in sys.modules.values():
Note in ln 48: of …/Python3.framework/Versions/3.7/lib/python3.7/linecache.py
downgrade the python to 3.6 . python 3.7 is not supported Tensorflow https://www.pyimagesearch.com/2019/01/30/macos-mojave-install-tensorflow-and-keras-for-deep-learning/
or
you can create a anaconda env of python3.6
conda create -n tf_cpu6 pip python=3.6source activate tf_cpu6pip install --ignore-installed --upgrade tensorflow==1.15Had the same issue Clang 11.0.0, Python 3.7.3 macOS Catalina, your fix solved it for me.
Thank, I solve my problem.🤣
I haven’t touch the system one, but have install one with
brewand added an alias.On three different laptops (both running the Catalina)
works
Python 3.7.5 (default, Nov 1 2019, 02:16:23) [Clang 11.0.0 (clang-1100.0.33.8)] on darwin
works
Python 3.7.4 Clang 10.0.1
does not work
Python 3.7.3 (default, Oct 11 2019, 19:39:43) [Clang 11.0.0 (clang-1100.0.33.12)] on darwin
LY, works!
Same issue, fresh macOS Catalina, virtualenv , i just update python to 3.7.5 , i try it and its works!