2016-11-24 674 views
0

我已經安裝了tensorflow版本r0.11。AttributeError:模塊'tensorflow'沒有屬性'reset_default_graph'

在我的文件名cartpole.py我已導入tensorflow

import tensorflow as tf 

,並使用它:

tf.reset_default_graph() 

試圖運行我的PyCharm項目中,我得到這個錯誤:

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

我該如何解決這個錯誤?

+0

你能否提供一些更多的代碼?我有一種感覺,你可能沒有正確導入東西 – martianwars

+0

或者你可能已經在項目中命名了一個文件'tensorflow.py' – martianwars

回答

1

你通常導入tensorflow通過寫作,

import tensorflow as tf 

這有可能是你在你的項目tensorflow.py命名爲文件和import聲明從該文件導入。

或者,你可以試試這個,

from tensorflow.python.framework import ops 
ops.reset_default_graph() 
+0

我試過這個提示。但是,這發生:命令 「蟒蛇setup.py egg_info」 失敗,錯誤代碼1 我用: PIP安裝--upgrade的setuptools 或 的easy_install -U setuptools的 但沒有任何幫助。 – magnp

+0

我的文件名是* cartpole.py * 我已經導入: *進口tensorflow如TF * 和使用 * tf.reset_default_graph()* – magnp

+1

您應該將這些詳細信息添加到您的問題。我認爲這是一個PyCharm特定問題。你有沒有嘗試在另一個文件夾中打開python終端,並輸入'import tensorflow as tf; tf.reset_default_graph()'? – martianwars

相關問題