[PYTHON] TensorFlow runtime Attribute Error: module'tensorflow' has no attribute'constant' is the first thing to doubt

I decided to try TensorFlow, and when I ran it, I got the following error ...

AttributeError: module 'tensorflow' has no attribute 'constant'

The executed file is as follows.

tensorflow.py


import tensorflow as tf

node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0) # also tf.float32 implicitly
print(node1, node2)

1st line It says ʻimport tensorflow as tf. Because the file name is tensorflow.py` It seems that it was an error that there was no'constant' because I was importing my own file instead of tensorflow of the library.

So ** Rename the file and it will work! ** **

$ python tensorflowrun.py
Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0", shape=(), dtype=float32)

Rename it to something other than tensorflow.py.

Those who touch Python for the first time or those who touch Python for the first time in a long time may want to doubt the file name if this happens.

Recommended Posts

TensorFlow runtime Attribute Error: module'tensorflow' has no attribute'constant' is the first thing to doubt
How to deal with module'tensorflow' has no attribute'〇〇'
[Dlib] Attribute Error: module'dlib' has no attribute ...
[Wandb] Attribute Error: module'wandb' has no attribute'init'
The first thing to check when a No Reverse Match occurs in Django
[Introduction to AWS] The first Lambda is Transcribe ♪
AttributeError: The story of solving module'tensorflow' has no attribute'log'.