Reputation: 1145
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:
Upvotes: 45
Views: 69506
Reputation: 1
I uninstalled keras version 2.10.0, and installed keras 2.6 version and it resolved it.
pip uninstall keras
pip install keras==2.6
and I uninstalled TensorFlow 2.5.0, and downloaded the latest version of TensorFlow,
pip uninstall TensorFlow
pip install TensorFlow
and it resolved the "Another metric with the same name already exists."
Upvotes: 0
Reputation: 31
In mine I just uninstalled the keras and it worked.
pip uninstall keras
Upvotes: 0
Reputation: 1660
In my case where was keras-nightly
that remained from tf-nightly
, I have used at some point, uninstall helped.
pip uninstall keras-nightly
Upvotes: 0
Reputation: 389
Both Tensorflow and Keras need to have the same version. The following solved my problem:
pip uninstall keras
pip uninstall Tensorflow
and then:
pip install tensorflow==2.6
pip install keras==2.6
Upvotes: 3
Reputation: 11
I had the same error, the problem is you are using tensorflow.keras
and the keras package already installed.
So uninstall tensorflow and keras and install this version of tensorflow which include keras :
pip uninstall tensorflow
pip uninstall keras
install tensorflow again with :
pip install tensorflow==2.6.0
Upvotes: 0
Reputation: 1
I had the same issue with importing tensorforce. Uninstalling Tensorforce and installing the newest stable version from githup fixed the issue for me
Upvotes: 0
Reputation: 116
I've solved this issue by removing keras from my dependencies and by using tensorflow~=2.6.0
as the tensorflow version. I'm using tf.keras
now.
Upvotes: 0
Reputation: 511
I encountered the same error while importing tensorflow v2.6 on jetson AGX xavier. It was the issue with the jetpack release not compatible with the version. Thus was resolved by downgrading the tensorflow to v2.5. $ sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v46 tensorflow==2.5.0+nv21.8
Upvotes: 0
Reputation: 61
After some query, the issue should be related to the Keras package version of the
problem. One solution, that I do not know why yet, but verified, is as follows:
1 --> uninstall the existing Keras package (the blogger is currently wrong version 2.7) by:
pip uninstall keras
2 --> install a specific version of the Keras package; I have installed version 2.6.0 with:
pip install keras==2.6.0
Upvotes: 6
Reputation: 646
I just had the same error (AlreadyExistsError: Another metric with the same name already exists.
).
I am using Anaconda with pip as package manager and I did not want to remove the entire anaconda environment as suggested in other answers.
I saw that the versions of my TensorFlow-related packages did not match via pip freeze | grep tensor
and pip freeze | grep keras
.
As a solution, I uninstalled all TensorFlow related packages (e.g. pip uninstall tensorflow
) and reinstalled them (e.g. pip install tensorflow
).
These steps solved the issue for me.
Upvotes: 0
Reputation: 86
By now you can upgrade to Tensorflow 2.7.0, alternatively, if you don't plan to use keras on its own (tensorflow.keras is actually a rather large repository so you can likely get by without keras) you can do "pip uninstall keras" as the issue comes from the program seeing two versions of keras (tf.keras and keras) that both have the accompanying method, i.e. from tensorflow.keras import Sequential and from keras import Sequential.
Tensorflow will naturally install Keras with it so if you update Keras to 2.6.0 you'll have to upgrade again to 2.7.0 (which I'm using and isn't presenting this issue) or uninstall Keras again.
Hope this helps :)
Upvotes: 0
Reputation: 442
I have solved the issue by updating tensorflow from 2.6.0 to 2.7.0
Upvotes: 0
Reputation: 11
Solved; I tried in MAC OS
Upvotes: 1
Reputation: 169
Solved!- I had same issue, and what I did is to delete my virtual environment and create new one, reinstall required libraries!
Upvotes: 0
Reputation: 4190
TL;DR: Ensure the Keras version matches the Tensorflow version
I am experiencing the same thing with:
The core issue appears to be that there are two Keras packages installed:
<site-packages>/keras
<site-packages/tensorflow/python/keras
If you look at the release notes for 2.6: https://github.com/tensorflow/tensorflow/releases/tag/v2.6.0
Keras been split into a separate PIP package (keras), and its code has been moved to the GitHub repositorykeras-team/keras. The API endpoints for tf.keras stay unchanged, but are now backed by the keras PIP package. The existing code in tensorflow/python/keras is a staled copy and will be removed in future release (2.7). Please remove any imports to tensorflow.python.keras and replace them with public tf.keras API instead.
For some reason, it is still importing from both packages which is triggering the valid exception (only one Keras instance should be imported)
Digging a bit further, it looks like Keras-2.7 was being installed, reverting to Keras-2.6 resolved the issue:
pip install keras==2.6.*
For some reason: https://github.com/tensorflow/tensorflow/blob/v2.6.1/tensorflow/tools/pip_package/setup.py#L106
Is not working, maybe a bug in PIP?
Upvotes: 62
Reputation: 1569
I also experienced this error after mixing the installation of tensorflow dependencies with both pip and conda. I was unable to fix by uninstalling/reinstalling tensorflow via either pip or conda.
My fix was installing tensorflow (v2.6.0) in a new virtual environment via the latest version of pip.
Upvotes: 2
Reputation: 21435
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.
Upvotes: 11