简体   繁体   English

TensorFlow:模块'__main__'没有属性'main'

[英]TensorFlow: module '__main__' has no attribute 'main'

I am working on image recognition with Tensorflow following this tutorial https://www.tensorflow.org/tutorials/layers . 我正在使用Tensorflow进行图像识别,遵循本教程https://www.tensorflow.org/tutorials/layers When I run the first chunk of codes, including "if name == " main ":", I get an error. 当我运行第一块代码时,包括“if name ==” main “:”,我收到错误。

if __name__ == "__main__":
  tf.app.run()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-20-a542ecc63e7e> in <module>()
     12 
     13 if __name__ == "__main__":
---> 14   tf.app.run()

~/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py in run(main)
     27   f = flags.FLAGS
     28   flags_passthrough = f._parse_flags()
---> 29   main = main or sys.modules['__main__'].main
     30   sys.exit(main(sys.argv[:1] + flags_passthrough))

AttributeError: module '__main__' has no attribute 'main'

What is the problem and how can I solve this? 有什么问题,我该如何解决?

I am using Python 3.6.2 under Anaconda environment on Jupiter Notebook. 我在Jupiter Notebook上的Anaconda环境下使用Python 3.6.2。

You don't need to use main module checker like this: 您不需要像这样使用主模块检查器:

if __name__ == "__main__":
  tf.app.run()

If you are on Jupiter notebook. 如果你在Jupiter笔记本上。 This was probable an error in the documentation. 这可能是文档中的错误。 Now you can check and this kind of checker is gone. 现在你可以检查 ,这种检查器已经消失了。

You would need to use that as an entry point if you create a python .py script. 如果您创建python .py脚本,则需要将其用作入口点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:模块'__main__'没有属性'cleaner' - AttributeError: module '__main__' has no attribute 'cleaner' AttributeError: 模块 '__main__' 没有属性 'AverageWordLengthExtractor' - AttributeError: module '__main__' has no attribute 'AverageWordLengthExtractor' pickle/joblib AttributeError: 模块 &#39;__main__&#39; 在 pytest 中没有属性 &#39;thing&#39; - pickle/joblib AttributeError: module '__main__' has no attribute 'thing' in pytest Pickle 序列化:模块 &#39;__main__&#39; 没有属性 &#39;tokenize&#39; - Pickle serialization: module '__main__' has no attribute 'tokenize' unittest:AttributeError:模块'__main__'没有属性'C:\ ...' - unittest: AttributeError: module '__main__' has no attribute 'C:\…' 模块'__main__'在jupyter中没有属性'__spec__' - module '__main__' has no attribute '__spec__' in jupyter 导入错误:执行 pip -e 后,模块“main”没有属性“__main__” - ImportError: module 'main' has no attribute '__main__' after doing pip -e 查找“pip”的模块规范时出错(AttributeError:模块“__main__”没有属性“__file__”) - Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__') Pydoop mapreduce“ AttributeError:模块&#39;wordcount_minimal&#39;没有属性&#39;__main__&#39;” - Pydoop mapreduce “AttributeError: module 'wordcount_minimal' has no attribute '__main__'” 用于单元测试的python3:AttributeError:模块&#39;__main__&#39;没有属性“内核......” - python3 for unit test: AttributeError: module '__main__' has no attribute “kernel…”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM