Error importing tensorflow "AlreadyExistsError: Another metric with the same name already exists."

ghz 1years ago ⋅ 5989 views

Question

I am running this simple code on Spyder 3.3 with Python 3.7 and Tensorlow 2.0:

import tensorflow as tf
print(tf.__version__)

When I try to run it again in the same IPython console, I get the following error:

File "/home/rodrigo/.local/lib/python3.7/site- packages/tensorflow_core/python/eager/monitoring.py", line 121, in init self._metric = self._metric_methods[self._label_length].create(*args)

AlreadyExistsError: Another metric with the same name already exists.

If I close the IPython console, and then open it again, it works fine. I am getting this error in every code that imports Tensorflow. Does anyone know how to solve this?

System configuration:

  • Ubuntu 19.04
  • Spyder 3.3.2
  • Python 3.7.3
  • IPython 5.8.0
  • TensorFlow 2.0.0-rc2

Answer

Tensorflow constructs singletons as side effects during import. Importing twice results in the singletons being created again, which is not supported. Please never import twice.