Reputation: 473
I installed tensorflow 1.8.0 as verified by pip show tensorflow
:
PS C:\> pip show tensorflow
Name: tensorflow
Version: 1.8.0
Summary: TensorFlow helps the tensors flow
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: c:\program files (x86)\python36-32\lib\site-packages
Requires: tensorboard, grpcio, absl-py, astor, wheel, protobuf, numpy, six,
gast, termcolor
Required-by:
PS C:\>
But when I tried to test a simple program named tensorflow.py
:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
I received an error:
PS C:\Users\Steven\.atom> python .\tensorflow.py
Traceback (most recent call last):
File ".\tensorflow.py", line 1, in <module>
import tensorflow as tf
File "C:\Users\Steven\.atom\tensorflow.py", line 2, in <module>
hello = tf.constant('Hello, TensorFlow!')
AttributeError: module 'tensorflow' has no attribute 'constant'
I am running the command in Windows Power Shell. My OS is 64-bit Windows 10 with Python 3.6.5. Can someone suggest a solution?
Upvotes: 1
Views: 425
Reputation: 137182
Your file is named tensorflow.py
, causing it to shadow the tensorflow
module. When Python looks for tensorflow.constant
it will try to find it its definition in your file.
Rename your file to something different. Something like hello_tf.py
might be a good choice.
Upvotes: 2