tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone

Home Page:https://tensorflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RuntimeError: dictionary changed size during iteration

milg15 opened this issue · comments

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

I tried to reproduce locally, using python3 (3.6 in my case) and your instructions as well as forcing a virtual env with python 3.7.3.

In both cases, the code run ok for me :-/ I am on a Linux though, but I never encountered this before on a Mac, either

In your log I see that the error gets outside of the virtualenv and seems to be coming from there and not from TensorFlow.

Leaving open and will try more investigations

Same issue.

commented

I am experiencing this same issue as well. I am using MacOS Catalina. Steps to reproduce this:

python3 -m venv myenv-env
source myenv-env/bin/activate
pip install tensorflow
python -c 'import tensorflow'

I get the following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/hari/Projects/3DDetection/3DDetection-env/lib/python3.7/site-packages/tensorflow/__init__.py", line 98, in <module>
    from tensorflow_core import *
  File "/Users/hari/Projects/3DDetection/3DDetection-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/hari/Projects/3DDetection/3DDetection-env/lib/python3.7/site-packages/tensorflow/__init__.py", line 50, in __getattr__
    module = self._load()
  File "/Users/hari/Projects/3DDetection/3DDetection-env/lib/python3.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 "/Users/hari/Projects/3DDetection/3DDetection-env/lib/python3.7/site-packages/tensorflow_core/python/__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/Users/hari/Projects/3DDetection/3DDetection-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/hari/Projects/3DDetection/3DDetection-env/lib/python3.7/site-packages/google/protobuf/__init__.py", line 37, in <module>
    __import__('pkg_resources').declare_namespace(__name__)
  File "/Users/hari/Projects/3DDetection/3DDetection-env/lib/python3.7/site-packages/pkg_resources/__init__.py", line 84, in <module>
    __import__('pkg_resources.extern.packaging.requirements')
  File "/Users/hari/Projects/3DDetection/3DDetection-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/hari/Projects/3DDetection/3DDetection-env/lib/python3.7/site-packages/pkg_resources/extern/__init__.py", line 43, in load_module
    __import__(extant)
  File "/Users/hari/Projects/3DDetection/3DDetection-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/hari/Projects/3DDetection/3DDetection-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/hari/Projects/3DDetection/3DDetection-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/hari/Projects/3DDetection/3DDetection-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 "/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

Please let me know if you need more information

I have two MacBook Pro running Catalina - one installation was successful - the other one not. The successful one is an inplace upgrade of the OS, so there is ton's of old stuff like Xcode, brew, .... the not successful one is a clean install, no Xocde, no brew, but Developer Tools installed. I used the same commands as harrygov plus I added
pip install --upgrade pip
pip install --upgrade setup tools
If I compare "pip list" on both venv - they are exactly the same.

In milg15 error dump there was a reference to /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/init.py
On my unsuccessful machine I have the same error - but on my successful machine this path does not exists ... /Library/Developer/CommandLineTools/ only contains a usr folder...

Please ask if I can provide more info.

So this seems to be an issue with the installed Python. Can you compare Python version on both systems, including all version metadata?

mihaimaruseac@ankh:~$ python
Python 2.7.16 (default, Apr  6 2019, 01:42:57) 
[GCC 7.3.0] on linux2

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

>>> import tensorflow
>>> 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 am also having the same issue. #33183 (comment)
Python 3.7.3
Tensorflow 2.0
macOS Catalina

Same issue, fresh macOS Catalina, virtualenv, python3
Clang 11.0.0, Python 3.7.3

By replacing the line in linecache.py I have gotten past this:

            v = sys.modules.copy()
            for mod in v:

By replacing the line in linecache.py I have gotten past this:

            v = sys.modules.copy()
            for mod in v:

Had the same issue Clang 11.0.0, Python 3.7.3 macOS Catalina, your fix solved it for me.

modules = sys.modules.copy()
for mod in modules.values():

Just wanted to let you know that it's working now :)
I did a complete reinstall of macos Catalina (including erasing the disks), did an
xcode-select --install
downloaded python3, upgraded pip and setuptools
installed jupyter
created a virtual environment ... and magic ...

(venv) $ python
Python 3.7.5 (v3.7.5:5c02a39a0b, Oct 14 2019, 18:49:57)
[Clang 6.0 (clang-600.0.57)] on darwin

To be honest - I have no idea why my "old installations" made use of Clang 10.0.1 or even 11.0.0 ... here we are back on 6.0 ... and tensorflow can be installed and imported without any issues.

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.6
source activate tf_cpu6
pip install --ignore-installed --upgrade tensorflow==1.15

Python3.7 is supported by TensorFlow.

I am having the same issue I believe that the issue is Clang V11. Rather than revert back to Clang V6 I would have liked to replace a line in the file linecache.py but that file doesn't seem to exist on my local env.

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

For python 3.7.3 (native) on Catalina the following works (add list() to make a copy):

 for mod in list(sys.modules.values()): # for mod in sys.modules.values():

Note in ln 48: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py

commented

Same issue, fresh macOS Catalina, virtualenv , i just update python to 3.7.5 , i try it and its works!

Same issue using virtualenv, Python = 3.7.3, upgraded to 3.7.5 and works fine

Problem went away after switching back to Python 3.6.9

For python 3.7.3 (native) on Catalina the following works (add list() to make a copy):

 for mod in list(sys.modules.values()): # for mod in sys.modules.values():

Note in ln 48: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py

Thank, I solve my problem.🤣

I confirm, updates from 3.7.3 to 3.7.5 fix the issue on macOS Catalina (v10.15.1) 🎉

I confirm, updates from 3.7.3 to 3.7.5 fix the issue on macOS Catalina (v10.15.1) 🎉

How did you update on the OS X? Is it safe to update the native python?

I confirm, updates from 3.7.3 to 3.7.5 fix the issue on macOS Catalina (v10.15.1) 🎉

How did you update on the OS X? Is it safe to update the native python?

I haven't touch the system one, but have install one with brew and added an alias.

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

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

LY, works!

This seems to be an issue with macos, not tensorflow. As such, I'm going to go ahead and close the issue.

I confirm, updates from 3.7.3 to 3.7.5 fix the issue on macOS Catalina (v10.15.1) 🎉

How did you update on the OS X? Is it safe to update the native python?

I haven't touch the system one, but have install one with brew and added an alias.

Would you mind sharing how specifically (commands)? thank you.

commented

I just found out. This Error occurs by nesting keras in a loop. After i changed variables manually and removed it from inside the loop, there are no longer errors occuring.

commented

By replacing the line in linecache.py I have gotten past this:

            v = sys.modules.copy()
            for mod in v:

It's works for me, thanks.

for mod in sys.modules.values():

Thanks, this worked for me as a charm.
Changed to tensor flow 1.15 and just updated the linecache.py

For python 3.7.3 (native) on Catalina the following works (add list() to make a copy):

 for mod in list(sys.modules.values()): # for mod in sys.modules.values():

Note in ln 48: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py

It WORKS for me . I find it here: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py