AttributeError:module' tensorflow'没有属性'变量' " ERROR"

时间:2017-07-26 04:50:48

标签: python windows tensorflow anaconda

我已经使用了张量流一天,但是遇到了一些麻烦,当我导入张量流时,会出现AttributeError:' module'对象没有属性'变量'

我使用Windows10,Python 3.5.3,Anaconda-3 4.4.0

这是我的测试代码:

import tensorflow as tf
my_var = tf.Variable(tf.linspace(10.0, 13.0, 4)) 
with tf.Session() as sess:
    print (sess.run(my_var))

我收到了这个错误: Error

2 个答案:

答案 0 :(得分:0)

看起来你编写了一个模块random.py,它模糊了标准库的random模块。尝试重命名文件并检查错误是否消失。您可以告诉它在您发布的堆栈跟踪的底部导入random.py。

答案 1 :(得分:0)

将“变量”替换为“变量”,例如下面的代码给出错误:

initial_value=tf.random.normal(shape=(2,2))
a = tf.variable(initial_value)
print(a)

但是这段代码给出了成功的输出

initial_value=tf.random.normal(shape=(2,2))
a = tf.Variable(initial_value)
print(a)