2

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 Windows10, Python 3.5.3, Anaconda-3 4.4.0

here is my test code:

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))

I got this error: Error

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.