Linux 下使用 tensorflow-gpu 出现如下报错:
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 变成了一个没有任何内容的模块(导致 tensorflow 变为空的原因未知)。
卸载重装 tensorflow-gpu 。
(tensorflow) [root@master zz]# pip uninstall -y tensorflow
...
Proceed (y/n)? y
Successfully uninstalled tensorflow-gpu-2.0.0b1
(tensorflow) [root@master zz]# pip3 install tensorflow-gpu
Collecting tensorflow-gpu
Downloading tensorflow_gpu-2.2.0-cp35-cp35m-manylinux2010_x86_64.whl (516.2 MB)
|████████████████████████████████| 516.2 MB 30 kB/s
...
验证安装是否正确。
(tensorflow) [root@master zz]# python3
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
... # 冗余信息
>>> tf.add(1, 2).numpy()
...
3
>>> hello = tf.constant('Hello, TensorFlow!')
>>> hello.numpy()
b'Hello, TensorFlow!'
>>> tf.__version__
'2.2.0'
tensorflow 报错: AttributeError: module ‘tensorflow’ has no attribute ‘xxxx’
module ‘tensorflow’ has no attribute ‘constant’
本文地址:https://blog.csdn.net/kernelxiao/article/details/107316841
如对本文有疑问, 点击进行留言回复!!
PC-Arduino Serial communication using python
网友评论