Skip to content Skip to sidebar Skip to footer

Attributeerror: Module 'tensorflow' Has No Attribute 'variable' "error"

I have used tensor-flow for ONE day, but there come some troubles, when I import tensor-flow, there would be AttributeError: 'module' object has no attribute 'variable' I use Windo

Solution 1:

It looks like you have written a module, random.py, which shadows the standard library's random module. Try renaming the file and check if the error goes away. You can tell it's importing your random.py at the bottom of the stacktrace you posted.


Solution 2:

Replace 'variable' with 'Variable', for example following code gives error:

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

but this code gives successful output

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

Post a Comment for "Attributeerror: Module 'tensorflow' Has No Attribute 'variable' "error""