安装tensorflow-gpu后Jupyter Notebook出现ImportError问题求助
解决TensorFlow-GPU导入错误:
experimental_functions_run_eagerly找不到 核心原因
这个错误通常是TensorFlow版本不兼容导致的:experimental_functions_run_eagerly在TensorFlow 2.10及以上版本中已被移除,如果你刚安装的tensorflow-gpu是较新版本,但代码依赖旧API,就会触发这个问题。
可行解决方案
回退到兼容版本
卸载当前tensorflow-gpu,安装2.9.x系列(最后一个包含该API的稳定版本):pip uninstall -y tensorflow-gpu pip install tensorflow-gpu==2.9.2验证Jupyter环境的TensorFlow版本
Jupyter可能使用了和终端不同的Python环境,导致加载的版本不符合预期。在Jupyter单元格中运行以下代码确认:import tensorflow as tf print(tf.__version__)如果版本不对,切换到对应conda/pip环境后重启Jupyter。
替换为新版本API
若不想回退版本,用TensorFlow官方推荐的替代API实现相同功能:
原代码中的:from tensorflow.python.eager.def_function import experimental_functions_run_eagerly experimental_functions_run_eagerly(True)替换为:
import tensorflow as tf tf.config.run_functions_eagerly(True)
内容的提问来源于stack exchange,提问作者Ania Sikora
相关产品推荐
相关产品推荐

