How to install tensor-keras using conda? I have below error message. I see this error while importing below module Here i copied a snipped of my code what i am actually trying in my code
from tensorflow.keras.callbacks import ModelCheckpoint
import tensorflow as tf
callback=tf.keras.callbacks.ModelCheckpoint(filepath='Regressor_model.h5',
monitor='mean_absolute_error',
verbose=0,
save_best_only=True,
save_weights_only=False,
mode='auto')
I was successfully installed tensorflow in Anaconda prompt by using below commands.
conda create -n tf tensorflow
conda activate tf
conda install keras
By the way i restarted pycharm IDE a couple a times. I still have same error
conda create -n tf tensorflow conda activate tf conda install keras
Traceback (most recent call last):
File "C:\Users\rethi1\Anaconda-python\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-353837d93f8d>", line 1, in <module>
runfile('C:/Users/rethi1/PycharmProjects/pythonProject/stock_prediction_test/__init__.py', wdir='C:/Users/rethi1/PycharmProjects/pythonProject/stock_prediction_test')
File "C:\Program Files\JetBrains\PyCharm 2020.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2020.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/rethi1/PycharmProjects/pythonProject/stock_prediction_test/__init__.py", line 273, in <module>
from tensorflow.keras.callbacks import ModelCheckpoint
File "C:\Program Files\JetBrains\PyCharm 2020.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'tensorflow.keras'
I tried a simple code which imports and uses tensorflow module
import tensorflow as tf
# Initialize two constants
x1 = tf.constant([9,10,11,12])
x2 = tf.constant([5,6,7,8])
# Multiply
result = tf.multiply(x1, x2)
# Print the result
print(result)
Error looks similar to above unable to use the module
x1 = tf.constant([9,10,11,12])
AttributeError: module 'tensorflow' has no attribute 'constant'
Thanks in Advance!