AttributeError: module 'tensorflow' has no

2019-01-20 14:06发布

I have installed tensorflow version r0.11.

In my file name cartpole.py I have imported tensorflow:

 import tensorflow as tf  

and use it:

 tf.reset_default_graph()

Trying to run my project in PyCharm I get this error:

in <module>
tf.reset_default_graph()
AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'

How can I fix this error?

2条回答
别忘想泡老子
2楼-- · 2019-01-20 14:13

This also may caused you run your code in the wrong environment.

I install tensorflow-gpu in my ~/tensorflow virtualenv.

I can run the python3 code.py in the env with source ./tensorflow/bin/activate

But whenI ran python3 code.py in the env ~ without virtualenv, I sometimes may came to issues like

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

or

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

and some others

查看更多
干净又极端
3楼-- · 2019-01-20 14:20

You normally import tensorflow by writing,

import tensorflow as tf

It's possible that you have named a file in your project tensorflow.py and the import statement is importing from this file.

Alternatively, you can try this,

from tensorflow.python.framework import ops
ops.reset_default_graph()
查看更多
登录 后发表回答