【问题标题】:TensorFlow has no attributes at allTensorFlow 完全没有属性
【发布时间】:2016-05-17 06:43:26
【问题描述】:

我按照以下说明在我的系统上安装了 TensorFlow https://www.tensorflow.org/versions/r0.8/get_started/os_setup.html#download-and-setup 并尝试了 pip 安装和 anaconda 安装。我尝试运行几个示例,但没有一个有效。

>>> import tensorflow
>>> tensorflow.InteractiveSession()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'
>>> a = tensorflow.zeros((2,2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'zeros'

对于许多其他功能,我得到了同样的错误。我已经安装了支持 GPU 的 TensorFlow 0.8、Python 3.5.1 和 Ubuntu 15.10 64bit。我记得在我安装 Anaconda(3) 之前一切运行良好,我这样做是为了获得 Numpy 和 Scipy。之后我也有点弄乱了python路径。现在,当我尝试重新安装 TensorFlow 时,使用

sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl
tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl is not a supported wheel on this platform.

为了在我的系统上重置 python,我什至重新安装了 Ubuntu,但这并没有太大帮助。应该怎么做才能让事情顺利进行?

【问题讨论】:

  • 在 Python shell 中print dir(tensorflow) 得到什么结果?我怀疑 Python 正在从您的路径中获取不同的文件或目录 - 例如你在当前目录中有一个名为tensorflow.py 的文件吗?
  • @mrry 'print(dir(tensorflow))' 打印这个 '['doc', 'loader', 'name ', 'package', 'path', 'spec']'

标签: python tensorflow


【解决方案1】:

如果您已经从源代码编译并安装了 tensorflow。 安装完成后,从保存 tensorflow 源的 git clone 的文件夹(通常在 ~/tensorflow 中)出来,然后尝试以下测试,看看您是否已成功编译并安装它。

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

如果您仍在 tensorflow 文件夹中并尝试检查,则会导致以下错误或类似错误。

AttributeError: 模块 'tensorflow' 没有属性 'constant'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 2019-10-05
    • 2019-08-04
    相关资源
    最近更新 更多