Skip to main content
 首页 » 编程设计

python之"import ... as .."触发属性错误

2025年01月19日9kenshinobiy

当我使用“导入为”时

import tensorflow.python.ops.control_flow_ops as ass 

我收到“AttributeError:模块‘tensorflow’没有属性‘python’”

但是下面的代码是这样的

import tensorflow.python.ops.control_flow_ops 

工作正常

环境:python 3.6.3 + tensorflow 1.3.0

请您参考如下方法:

这是 TensorFlow 接口(interface)密封(例如从 import tensorflow as tf 中删除 tf.python 符号可见性)和 Python import semantics 的不幸组合. import tensorflow...as 语法只能访问公共(public) TensorFlow 符号,而 from tensorflow...import ...as 也可以访问没有 API stability guarantees 的私有(private)符号。 .