AttributeError: 模块“tensorflow"没有属性“python" [英] AttributeError: module 'tensorflow' has no attribute '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.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屋!