这个错误是因为TensorFlow更新后版本的更改,在tensorflow模块下“python”属性已经被删除。解决方法是将代码中引用“tensorflow.python”的地方改为“tensorflow”。例如:
原始代码:
import tensorflow as tf
sess = tf.Session() hello = tf.constant('Hello, TensorFlow!') print(sess.run(hello))
修改后的代码:
import tensorflow as tf
sess = tf.Session() hello = tf.constant('Hello, TensorFlow!') print(sess.run(hello))
这个解决方法适用于通过“tensorflow.python”引用代码时出现的问题,例如:
原始代码:
from tensorflow.python.ops import math_ops
修改后的代码:
from tensorflow.ops import math_ops
通过这种修改,代码就可以正常运行了。
上一篇:AttributeError:module'tensorflow'hasnoattribute'gfile'
下一篇:Attributeerror:module'teradatasql'hasnoattribute'connect'