属性错误:模块在 tensorflow 中没有属性
attribute errors: module has no attribute in tensorflow
我正在尝试 运行 我使用
的示例脚本
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__'
正如 Mitiku 指出的那样..安装有问题所以我重新安装了它..现在可以使用了..
print( dir(tf)) -- 这应该显示 tensorflow 下的包列表..
我的问题是 运行 版本 2 的 Tensorflow 1 脚本。
tf.app 在版本 2 中移动到 tf.compat.v1.app。有一个工具可以帮助自动升级到版本 2。
tf_upgrade_v2 --intree my_project/ --outtree my_project_v2/ --reportfile report.txt
我把它放在这里以防有人遇到同样的问题。
我正在尝试 运行 我使用
的示例脚本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__'
正如 Mitiku 指出的那样..安装有问题所以我重新安装了它..现在可以使用了..
print( dir(tf)) -- 这应该显示 tensorflow 下的包列表..
我的问题是 运行 版本 2 的 Tensorflow 1 脚本。
tf.app 在版本 2 中移动到 tf.compat.v1.app。有一个工具可以帮助自动升级到版本 2。
tf_upgrade_v2 --intree my_project/ --outtree my_project_v2/ --reportfile report.txt
我把它放在这里以防有人遇到同样的问题。