当前位置: 代码迷 >> 综合 >> AttributeError: module ‘tensorflow‘ has no attribute ‘InteractiveSession‘(亲测有效)
  详细解决方案

AttributeError: module ‘tensorflow‘ has no attribute ‘InteractiveSession‘(亲测有效)

热度:25   发布时间:2023-12-17 15:07:13.0

在运行Tensorflow时报错:

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

这其实不是包的安装错误,是因为在新的Tensorflow 2.0版本中已经移除了Session这一模块,改换运行代码:

sess = tf.InteractiveSession()

换成:

sess = tf.compat.v1.InteractiveSession()

同理,如果代码中还有类似的"tf.***"之类的代码,应该都要在其后加上"compat.v1."。

如果用着不习惯,那就降低Tensorflow的版本也可以:

pip install tensorflow==1.14

 

  相关解决方案