If as
is used to create an alias in python such as
import tensorflow as tf
why cannot I import using the same alias
import tensorflow as tf
from tf import keras
Gives me error
ModuleNotFoundError: No module named 'tf'
If as
is used to create an alias in python such as
import tensorflow as tf
why cannot I import using the same alias
import tensorflow as tf
from tf import keras
Gives me error
ModuleNotFoundError: No module named 'tf'
tf
is not intended to be a keyword or Module name. Searching about tf
will not be found in the Module list.
See this
The error is beacuse the,
from tf import keras
directly tries to find a module named tf
it does not tries to look for variable named tf or any other declaration of tf
in your code.
We can import a module with a specific name but the loading process is based on module name and not the alias you have created for it.
Hope this helps!
I think that while importing you have to use the original name as [Because tf is not a module,it is just a nickname for that library.]
from tensorflow import keras
and at the time of using it you can use
tf.keras()
(I am not 100% sure,you can try it.)