简体   繁体   中英

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 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:错误

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM