Python 模块';tensorflow';没有属性';常数';
我之前已经安装了tensorflow和gpu支持并开始工作。我试着安装了keras,之后什么都不能用了。我已经卸载了keras和tensorflow 我尝试按照tensorflow网页上的说明重新安装支持gpu的tensorfow(现在是1.9版)(顺便说一下,我正在运行Ubuntu18)。我试着运行代码Python 模块';tensorflow';没有属性';常数';,python,tensorflow,Python,Tensorflow,我之前已经安装了tensorflow和gpu支持并开始工作。我试着安装了keras,之后什么都不能用了。我已经卸载了keras和tensorflow 我尝试按照tensorflow网页上的说明重新安装支持gpu的tensorfow(现在是1.9版)(顺便说一下,我正在运行Ubuntu18)。我试着运行代码 import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
我得到了错误
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
Traceback (most recent call last):
File "<ipython-input-2-25b92e4d5dec>", line 2, in <module>
hello = tf.constant('Hello, TensorFlow!')
AttributeError: module 'tensorflow' has no attribute 'constant'
将tensorflow导入为tf
hello=tf.constant('hello,TensorFlow!')
sess=tf.Session()
打印(sess.run(hello))
回溯(最近一次呼叫最后一次):
文件“”,第2行,在
hello=tf.constant('hello,TensorFlow!')
AttributeError:模块“tensorflow”没有属性“constant”
我试着查看其他线程,有人建议在“常量”中大写C,但这也不起作用
任何建议都很好
谢谢,您的安装已损坏,执行以下操作应能使您回到正轨 你能试一下吗
pip install virtualenv
virtualenv venv
## Linux:
source venv/bin/activate
## Windows:
venv\Scripts\activate.bat
pip install tensorflow-gpu==1.9.0
python temp.py
如果这样做没有任何问题。您的python安装已损坏,我建议您手动删除python库中的所有内容
也许这会有帮助:
pip卸载tensorflow-y
pip卸载tensorflow gpu-y
pip卸载张力板-y
pip安装——升级tensorflow gpu==1.9.0-y
如果您已经使用了virtualenv,只需删除该文件夹并重新创建它我也有同样的问题,我错误地将我的文件命名为
tensorflow.py
。如果文件夹名为tensorflow,则会出现相同的问题
我刚刚用其他东西重命名了文件,它解决了问题。按照以下步骤操作:
由于某些原因,tensorflow的依赖项保留在系统中,因此从头开始创建可以解决问题。您的脚本名为“tensorflow.py”吗?不,是temp.py*同一目录中是否有另一个名为“tensorflow.py”的脚本?不幸的是,我看不清楚。不过我会继续看的。谢谢。在阅读本文之前,我卸载了anaconda和tensorflow,并重新安装了它们。现在我有了错误ModuleNotFoundError:没有名为“tensorflow”的模块。但我认为这是因为我需要在bash.rc中插入一行代码。如果这样做行得通,我会给你答案。我的评论仍然有效,试着使用一个虚拟机。我现在正在按照你的指示工作——我建议你重新措辞一点(实际上更多的是删除部分)。你想避免(即使只是乍一看)这是一个“自我工具”的印象。