导入TensorFlow Hub报错:module 'tensorflow.tools.docs.doc_controls'无inheritable_header属性
问题解决思路
报错根因
该错误由tensorflow-estimator版本与TensorFlow 2.6不兼容导致:高版本tensorflow-estimator依赖的文档控制工具属性inheritable_header,在TensorFlow 2.6自带的tensorflow.tools.docs.doc_controls模块中不存在,触发属性缺失报错。
可用解决方案(按生效速度排序)
- 方案1(最快生效):直接安装匹配TensorFlow 2.6的estimator版本,执行命令:
pip install tensorflow-estimator==2.6.0
安装完成后重新尝试导入tensorflow-hub即可。
- 方案2(版本完全对齐):如果方案1执行后仍报错,卸载现有相关包后重新安装匹配的整套版本,执行命令:
pip uninstall tensorflow tensorflow-hub tensorflow-estimator -y pip install tensorflow==2.6 tensorflow-hub==0.12.0 tensorflow-estimator==2.6.0
- 方案3(临时规避,无需修改依赖):如果项目未使用tensorflow-hub的estimator相关功能,可在导入hub前添加环境变量配置,跳过estimator模块加载:
import os os.environ['TFHUB_DISABLE_ESTIMATOR_IMPORT'] = '1' import tensorflow_hub as hub
验证方法
安装完成后执行pip list | grep tensorflow,确认tensorflow、tensorflow-hub、tensorflow-estimator三个包的版本分别为2.6、0.12.0、2.6.0即可。
内容的提问来源于stack exchange,提问作者yash shah
相关产品推荐
相关产品推荐

