tensorflow首次运行问题

时间:2018-07-23 00:35:03

标签: python tensorflow python-3.6

我刚刚安装了tesorflow cpu,这是我的代码

import tensorflow as tf
node1 = tf.constant(3.0)
node2 = tf.constant(4.0)
print(node1)

这不会运行,并显示以下错误:

Traceback (most recent call last):
  File "c:\Python\Python36\cssi\final_project.py", line 1, in <module>
    import tensorflow as tf
  File "c:\Python\Python36\cssi\tensorflow.py", line 2, in <module>
    node1 = tf.constant(3.0)
AttributeError: module 'tensorflow' has no attribute 'constant'

请帮助

1 个答案:

答案 0 :(得分:1)

只需重命名脚本即可。创建名为 tensorflow.py 的脚本时,我遇到了同样的问题。将其重命名为 test.py 并查看其工作原理。

(base) D:\>python tensorflow.py
Traceback (most recent call last):
  File "tensorflow.py", line 1, in <module>
    import tensorflow as tf
  File "D:\tensorflow.py", line 2, in <module>
    node1 = tf.constant(3.0)
AttributeError: module 'tensorflow' has no attribute 'constant'

(base) D:\>python test.py
Tensor("Const:0", shape=(), dtype=float32)