Python import tensflow.keras error solution

 

When using tensflow.keras, you may encounter the following errors:

The reason for the problem is that there is an extra layer of python between tensorflow and keras

Both the correct path for import should be import tensorflow.python.keras

The solution steps are as follows:

1 Import tensorflow first, if not, go to download tensorflow

>>> import tensorflow
>>> import tensorflow.keras

2 Import the kernels in tensorflow, the second command above

3 Import in another way

>>> from tensorflow import keras
>>> from tensorflow import keras as kr

from tensorflow import keras as kr is equivalent to import tensorflow.python.keras as kr

Guess you like

Origin blog.csdn.net/qq_39463175/article/details/107952792