ImportError: cannot import name 'GceClusterResolver' - python

I am following the guide for installing TensorFlow Slim, and I faced this error.
ImportError: cannot import name 'GceClusterResolver'
I searched online and found some questions on Stack Overflow regarding "import error cannot import name xxx", but none of them is the same as mine. I've tried their solutions too but they didn't work.
This is the complete error message. Any help is greatly appreciated.
python -c "import tensorflow.contrib.slim as slim; eval = slim.evaluation.evaluate_once"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/__init__.py", line 31, in <module>
from tensorflow.contrib import cluster_resolver
File "/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/cluster_resolver/__init__.py", line 26, in <module>
from tensorflow.python.distribute.cluster_resolver.gce_cluster_resolver import GceClusterResolver
ImportError: cannot import name 'GceClusterResolver'

I found out that i was using tflearn with tensorflow 2 but tflearn is not compatible with tensorflow 2. I just falled back to a tensorflow 1 version.
# uninstall both libs
pip uninstall tensorflow
pip uninstall tflearn
# install the compatible version
pip install tflearn
pip install tensorflow==1.15

Related

TensorFlow ModuleNotFoundError: No module named 'official.nlp.bert'

I'm following the TenslorFlow TFlite basic text classification tutorial, but the third import line throws an error:
from tensorflow_examples.lite.model_maker.core.data_util import image_dataloader
ModuleNotFoundError: No module named 'official.nlp.bert'
I installed TensorFlow with pip install tensorflow and the tflite model maker with pip install -q tflite-model-maker.
I've also installed all the official models with pip install tf-models-official.
I can see the BERT model on the official models GitHub as well, so it should be in there.
How can I install the bert model?
Full error:
Traceback (most recent call last):
File "...\Downloads\tf_setup.py", line 6, in <module>
from tflite_model_maker import model_spec
File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tflite_model_maker\__init__.py", line 16, in <module>
from tensorflow_examples.lite.model_maker.core.data_util import image_dataloader
File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_examples\lite\model_maker\__init__.py", line 17, in <module>
from tensorflow_examples.lite.model_maker.core.data_util import text_dataloader
File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_examples\lite\model_maker\core\data_util\text_dataloader.py", line 31, in <module>
from tensorflow_examples.lite.model_maker.core.task import model_spec as ms
File "...\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow_examples\lite\model_maker\core\task\model_spec.py", line 37, in <module>
from official.nlp.bert import configs as bert_configs
ModuleNotFoundError: No module named 'official.nlp.bert'
What is your Python version? I encountered the exact same error while I was using Python 3.10. My tflite-model-maker was 0.1.x version despite I tried to install the latest one which is 0.4.0. I wanted to update it but I got more errors about "No matching distribution" for tflite-model-maker and tflite-support. After I installed and changed my Python interpreter (I'm using PyCharm) to Python 3.9.13 and reinstall tflite-model-maker, the error is gone.

cannot import name '_registerMatType' from 'cv2.cv2' The other solutions don't work

I have been trying to run a script for object detection and I keep getting the following error,I have seen the same question being answered but I didn't get the desired result while reinstalling open cv
Traceback (most recent call last):
File "model_main_tf2.py", line 32, in <module>
from object_detection import model_lib_v2
File "/usr/local/lib/python3.7/dist-packages/object_detection/model_lib_v2.py", line 29, in <module>
from object_detection import eval_util
File "/usr/local/lib/python3.7/dist-packages/object_detection/eval_util.py", line 36, in <module>
from object_detection.metrics import lvis_evaluation
File "/usr/local/lib/python3.7/dist-packages/object_detection/metrics/lvis_evaluation.py", line 23, in <module>
from lvis import results as lvis_results
File "/usr/local/lib/python3.7/dist-packages/lvis/__init__.py", line 5, in <module>
from lvis.vis import LVISVis
File "/usr/local/lib/python3.7/dist-packages/lvis/vis.py", line 1, in <module>
import cv2
File "/usr/local/lib/python3.7/dist-packages/cv2/__init__.py", line 9, in <module>
from .cv2 import _registerMatType
ImportError: cannot import name '_registerMatType' from 'cv2.cv2'
The same thing occurred to me then i update my all opencv modules:
C:\Windows\system32>pip list |findstr opencv
opencv-contrib-python 4.5.3.56
opencv-python 4.5.2.52
opencv-python-headless 4.5.5.62
The version isn't same. So I first uninstall all opencv modules:
pip uninstall opencv-python-headless
pip uninstall opencv-python
pip uninstall opencv-contrib-python
Then reinstall all opencv modules in 4.5.5.62 version.
pip install opencv-python==4.5.5.62
pip install opencv-python-headless==4.5.5.62
pip install opencv-contrib-python==4.5.5.62
The problem is the resolved.

Jupiter notebook run error: AttributeError: module 'importlib_metadata' has no attribute 'version'

Originally, Jupyter notebook was running well without any problems.
But after installing tensorflow and keras today, it doesn't work.
Error message:
Traceback (most recent call last):
File "C:\Anaconda3\Scripts\jupyter-notebook-script.py", line 6, in <module>
from notebook.notebookapp import main
File "C:\Anaconda3\lib\site-packages\notebook\notebookapp.py", line 85, in <module>
from .services.contents.manager import ContentsManager
File "C:\Anaconda3\lib\site-packages\notebook\services\contents\manager.py", line 17, in <module>
from nbformat import sign, validate as validate_nb, ValidationError
File "C:\Anaconda3\lib\site-packages\nbformat\__init__.py", line 32, in <module>
from .validator import validate, ValidationError
File "C:\Anaconda3\lib\site-packages\nbformat\validator.py", line 12, in <module>
from .json_compat import get_current_validator, ValidationError
File "C:\Anaconda3\lib\site-packages\nbformat\json_compat.py", line 10, in <module>
import jsonschema
File "C:\Anaconda3\lib\site-packages\jsonschema\__init__.py", line 34, in <module>
__version__ = metadata.version("jsonschema")
AttributeError: module 'importlib_metadata' has no attribute 'version'
There is a problem with your importlib_metadata package, you can try uninstall it first and then forcing out a new installation with the following commands:
pip uninstall importlib_metadata
pip install importlib_metadata --force-reinstall
It worked for me.
This is a problem with the Anaconda version upgrade.
You can solve this with the following command that worked for me.
conda install -c conda-forge importlib_metadata
For me, the same error happened after VSCode proposed me to install a tensorboard plugin and I pressed yes. (MacOS 11.4, Conda 4.10.3)
It appears that it introduced some kind of version mismatch for multiple packages in the environment.
The following fixed the problem:
conda update --all

AttributeError: module 'tensorflow' has no attribute 'compat'

Since my CPU doesn't support AVX instructions and I want to install a newer version of Tensorflow (>= 2.0), I installed a tensorflow wheel for my Python version from https://github.com/fo40225/tensorflow-windows-wheel using pip
However, when trying to import tensorflow, I get the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
from tensorflow_core import *
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\__init__.py", line 45, in <module>
from . _api.v2 import compat
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\__init__.py", line 23, in <module>
from . import v1
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\_api\v2\compat\v1\__init__.py", line 664, in <module>
from tensorflow_estimator.python.estimator.api._v1 import estimator
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\__init__.py", line 10, in <module>
from tensorflow_estimator._api.v1 import estimator
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 10, in <module>
from tensorflow_estimator._api.v1.estimator import experimental
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\_api\v1\estimator\experimental\__init__.py", line 10, in <module>
from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\canned\dnn.py", line 33, in <module>
from tensorflow_estimator.python.estimator import estimator
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 53, in <module>
from tensorflow_estimator.python.estimator import util as estimator_util
File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_estimator\python\estimator\util.py", line 75, in <module>
class _DatasetInitializerHook(tf.compat.v1.train.SessionRunHook):
AttributeError: module 'tensorflow' has no attribute 'compat'
I have searched, but not found anybody who encountered the same issue using tensorflow wheel (just trying to install tensorflow via "pip install tensorflow" isn't going to work for me, as I will run into the ImportError: DLL load failed-error).
It seems tensorflow is not installed in your system in the proper way which causes this error.
You need to install tensorflow using any of the below command:
pip install tensorflow
pip install tensorflow-gpu # to install tensorflow for gpu support
pip install tensorflow==2.4.0 # to install a specific tensorflow version
For Anaconda environment in jupyter notebook, use below code:
conda install tensorflow
conda install tensorflow-gpu # to install tensorflow for gpu support
Please follow this link which has step wise instructions to install tensorflow in your system.

Can't Get PyDot to Work in Python 3.5

While using Keras library for machine learning, I keep getting the error:
Traceback (most recent call last):
File "rnn2.py", line 253, in <module>
from keras.utils.visualize_util import plot
File "C:\Program Files\Anaconda2\envs\py35\lib\site-packages\keras\utils\visualize_util.py", line 13, in <module>
raise RuntimeError('Failed to import pydot. You must install pydot'
RuntimeError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.
My system is Windows 10, Anaconda 3.5 environment. I have tried all of the solutions mentioned in github issues and stack overflow:
like installing pyparsing , pydot-ng, graphviz etc. Nothing is working, I keep getting the error.
What to install to remove the error? Please help. Thanks.

Categories