Why do I get a ModuleNotFoundError: No module named 'tf'
for:
import tensorflow as tf
import tf.keras.models
doesn't Python reference tf
as an alias to tensorflow
from the line import tensorflow as tf
?
Why do I get a ModuleNotFoundError: No module named 'tf'
for:
import tensorflow as tf
import tf.keras.models
doesn't Python reference tf
as an alias to tensorflow
from the line import tensorflow as tf
?
When you do
import tensorflow as tf
it has already imported all the sub-modules as tensorflow is a package.
So, to get the models, you just need to access it, no need to import
tf.keras.models
If you wanna import a specific module, then,
from tensorflow.keras import models
Try using with tensorflow
import tensorflow as tf
import tensorflow.keras.models
Or you can use it as
import tensorflow as tf
sys.modules['tf'] = tensorflow
import tf.keras.models