使用';导入时,Python模块没有属性错误;as';

使用';导入时,Python模块没有属性错误;as';,python,Python,我想从Tensorflow库导入Keras。所以我做了以下事情: import tensorflow.python.keras as keras 但此导入会抛出错误: AttributeError: module 'tensorflow' has no attribute 'python' 似乎以下两种导入都正常工作: import tensorflow.python.keras from tensorflow.python import keras 对我来说,import tensorf

我想从Tensorflow库导入Keras。所以我做了以下事情:

import tensorflow.python.keras as keras
但此导入会抛出错误:

AttributeError: module 'tensorflow' has no attribute 'python'
似乎以下两种导入都正常工作:

import tensorflow.python.keras
from tensorflow.python import keras

对我来说,
import tensorflow.python.keras as keras
from tensorflow.python import keras
是相同的,但看起来不是真的。这两种导入之间有什么区别?

您应该尝试以下方法:

import tensorflow as tf
import tensorflow 

from tensorflow import keras
from keras.layers import Dense
# ...
第一行帮助您使用带有
tf
短名称(asname)的
tensorflow
模块


对于asname,您可以选中此项。

您应该尝试以下内容:

import tensorflow as tf
import tensorflow 

from tensorflow import keras
from keras.layers import Dense
# ...
第一行帮助您使用带有
tf
短名称(asname)的
tensorflow
模块


对于asname,您可以检查它。

导入tensorflow.python.keras作为keras
适用于
tensorflow==1.13.1
Python3.7.3
您可以发布您的tf版本和python版本吗?我正在使用
Python3.6
tensorflow==1.13.1
请参见,如何导入
keras
import tensorflow.python.keras as keras
适用于
tensorflow==1.13.1
python 3.7.3
您能发布您的tf版本和python版本吗?我正在使用
python 3.6
tensorflow==1.13.1
请参见,如何导入
keras