AttributeError:模块"tensorflow"没有属性"python" [英] AttributeError: module 'tensorflow' has no attribute 'python'

查看:138
本文介绍了AttributeError:模块"tensorflow"没有属性"python"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>import tensorflow

>import tensorflow.contrib

>tensorflow.contrib

module 'tensorflow.contrib' from 'D:\\ProgramData\\Anaconda3\\lib\\site-packages\\tensorflow\\contrib\\__init__.py'

>import tensorflow.python

>tensorflow.python

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'python'

如您所见,我在cmd(win 10)中运行此代码. "import tensorflow.contrib"和"import tensorflow.python"都可以,但是命令"tensorflow.contrib"和"tensorflow.python"不同.一个返回目录,另一个返回AttributeError.

As you can see, I run this code in a cmd(win 10). Both "import tensorflow.contrib" and "import tensorflow.python" are OK, but commands "tensorflow.contrib" and "tensorflow.python" are different. One returns a directory and the other returns AttributeError.

有人知道为什么吗?

推荐答案

tensorflow.__init__()在从其中导入所有内容后,显式删除其对tensorflow.python模块的引用.

tensorflow.__init__() explicitly deletes its reference to the tensorflow.python module after importing everything from it.

这样做的原因是为了提供对顶级tensorflow命名空间中python包中包含的子模块的访问. tensorflow.core包中的一些内容也已导入,并在tensorflow名称空间中可用.

The reason for that is to provide access to the submodules contained in the python package in the top-level tensorflow namespace. A few things from the tensorflow.core package are also imported and made available in the tensorflow namespace.

我认为直接导入tensorflow.python的想法不是 .打算由应用程序使用的python的类,对象和子模块可以通过import tensorflow轻松获得.

I think that the idea is not to import tensorflow.python directly. Those classes, objects, and submodules of python that are intended to be used by applications are made available simply by import tensorflow.

这篇关于AttributeError:模块"tensorflow"没有属性"python"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆