首页 > 解决方案 > ImportError:无法导入名称“GceClusterResolver”

问题描述

我正在按照安装 TensorFlow Slim 的指南进行操作,但遇到了这个错误。

ImportError: cannot import name 'GceClusterResolver'

我在网上搜了一下,在 Stack Overflow 上发现了一些关于“ import error cannot import name xxx ”的问题,但没有一个和我的一样。我也尝试过他们的解决方案,但没有奏效。

这是完整的错误信息。任何帮助是极大的赞赏。

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'

标签: pythontensorflowimporterrortensorflow-slim

解决方案


我发现我正在使用tflearnwithtensorflow 2但 tflearn 与 tensorflow 2 不兼容。我刚刚退回到 tensorflow 1 版本。

# uninstall both libs
pip uninstall tensorflow
pip uninstall tflearn

# install the compatible version
pip install tflearn
pip install tensorflow==1.15

推荐阅读