Traceback Error: ModuleNotFoundError: No module named 'tensorflow.keras'
Traceback Error: ModuleNotFoundError: No module named 'tensorflow.keras'
如何使用conda安装tensor-keras?我有以下错误消息。我在导入以下模块时看到此错误
在这里,我复制了一段我的代码,我在我的代码中实际尝试的是什么
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')
我使用以下命令在 Anaconda 提示符下成功安装了 tensorflow。
conda create -n tf tensorflow
conda 激活 tf
conda 安装 keras
顺便说一下,我重新启动了 pycharm IDE 几次。我仍然有同样的错误
conda create -n tf tensorflow
conda 激活 tf
conda 安装 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'
我尝试了一个导入并使用 tensorflow 模块的简单代码
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)
错误类似于上面无法使用模块
x1 = tf.constant([9,10,11,12])
AttributeError: module 'tensorflow' has no attribute 'constant'
提前致谢!
我想出了一个现在有效的灵魂。我将我的 py 版本降级到 python 3.6.8 推荐遵循:tensorflow.org/install/pip#system-install 问题的原因非常明显。大多数用户可能会遇到同样的问题。使用完全超出范围的非兼容版本
作为初学者,大多数人最终都会遇到兼容性问题。我强烈建议遵循原始文档
如何使用conda安装tensor-keras?我有以下错误消息。我在导入以下模块时看到此错误 在这里,我复制了一段我的代码,我在我的代码中实际尝试的是什么
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')
我使用以下命令在 Anaconda 提示符下成功安装了 tensorflow。
conda create -n tf tensorflow
conda 激活 tf
conda 安装 keras
顺便说一下,我重新启动了 pycharm IDE 几次。我仍然有同样的错误
conda create -n tf tensorflow conda 激活 tf conda 安装 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'
我尝试了一个导入并使用 tensorflow 模块的简单代码
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)
错误类似于上面无法使用模块
x1 = tf.constant([9,10,11,12])
AttributeError: module 'tensorflow' has no attribute 'constant'
提前致谢!
我想出了一个现在有效的灵魂。我将我的 py 版本降级到 python 3.6.8 推荐遵循:tensorflow.org/install/pip#system-install 问题的原因非常明显。大多数用户可能会遇到同样的问题。使用完全超出范围的非兼容版本 作为初学者,大多数人最终都会遇到兼容性问题。我强烈建议遵循原始文档