Miniconda环境导入tensorflow_hub遇AttributeError问题求助
解决TensorFlow与TensorFlow Estimator版本不兼容导致的AttributeError问题
问题根源
你的环境中TensorFlow 2.4.1和TensorFlow Estimator 2.6.0版本不匹配,高版本的estimator调用了低版本TensorFlow中不存在的内部API(tf.compat.v2.__internal__.monitoring),即使你没有TPU,estimator模块的导入过程也会触发这个错误。同时tensorflow-hub 0.13.0与TensorFlow 2.4.1的兼容性也存在问题。
解决步骤
- 激活你的Miniconda环境:
conda activate CFS
- 卸载当前不兼容的包:
pip uninstall -y tensorflow-estimator tensorflow-hub
- 安装与TensorFlow 2.4.1匹配的版本:
pip install tensorflow-estimator==2.4.0 tensorflow-hub==0.12.0
- 验证安装成功:
运行以下代码测试导入是否正常:
import tensorflow as tf import tensorflow_hub as hub print("TensorFlow版本:", tf.__version__) print("TensorFlow Hub版本:", hub.__version__)
如果没有报错,说明问题已解决。
内容的提问来源于stack exchange,提问作者BeginnersMindTruly
相关产品推荐
相关产品推荐

