【问题标题】:attribute errors: module has no attribute in tensorflow属性错误:模块在 tensorflow 中没有属性
【发布时间】:2017-10-25 06:41:50
【问题描述】:

我正在尝试运行我使用的示例脚本

import tensorflow as tf
def main():
  if __name__ = '__main__':
  tf.app.run(main = main)

引发错误:

AttributeError: module 'tensorflow' has no attribute 'app'

但是当我运行它时:

from tensorflow.python.platform import app

它运行良好..我使用的python版本是3.6.1和tensorflow版本:0.1.8

其实还是

print(tf.__version__)

显示属性错误..

AttributeError: module 'tensorflow' has no attribute '__version__'

【问题讨论】:

  • print(dir(tf)) 的输出是什么?
  • 这是输出:['doc', 'loader', 'name', 'package', 'path', 'spec', 'core', 'python']
  • 这些不是 tensorflow 的属性。您可能在工作目录中有名为 tensorflow.py 的文件。请检查
  • dir /s tensorflow.py 列出的文件总数:3 个文件全部命名为:pywrap_tensorflow.py
  • 您可以更改您的工作目录并从那里尝试吗?

标签: python tensorflow python-3.6


【解决方案1】:

正如 Mitiku 指出的那样.. 安装有问题,所以我重新安装了它.. 它现在可以工作了..

print(dir(tf)) -- 这应该显示 tensorflow 下的包列表..

【讨论】:

  • 为了清楚说明dir 显示了一个对象所具有的所有属性,在这种情况下,该对象是一个模块(属于 tensorflow 的包),它显示了该模块所具有的所有属性。跨度>
【解决方案2】:

我的问题是为版本 2 运行 Tensorflow 1 脚本。

tf.app 在版本 2 中移动到 tf.compat.v1.app。有一个工具可以帮助自动升级到版本 2。

tf_upgrade_v2 --intree my_project/ --outtree my_project_v2/ --reportfile report.txt

我把它放在这里以防有人遇到同样的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    • 2020-10-17
    • 1970-01-01
    • 2020-07-20
    • 2020-06-05
    相关资源
    最近更新 更多