gpt4 book ai didi

python - 模块 'tensorflow' 没有属性 'constant'

转载 作者:行者123 更新时间:2023-12-04 14:37:56 25 4
gpt4 key购买 nike

我之前安装了 tensorflow 并安装了 gpu 支持并正常工作。我尝试安装 keras 之后什么都不起作用了。我已经卸载了 keras 和 tensorflow。

我尝试按照 tensorflow 网页 https://www.tensorflow.org/install/install_linux 上的说明重新安装支持 gpu 的 tensorfow(现在是 1.9 版) (顺便说一下,我正在运行 ubuntu 18)。我尝试运行代码

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'

我尝试查看其他线程,有人建议将 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 uninstall tensorflow -y
  • pip uninstall tensorflow-gpu -y
  • pip uninstall tensorboard -y
  • pip install --upgrade tensorflow-gpu==1.9.0 -y

  • 如果您已经使用了 virtualenv,只需删除该文件夹并重新创建它 .

    关于python - 模块 'tensorflow' 没有属性 'constant',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51585095/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com