【问题标题】:Keras installed but can't import as it says keras module not foundKeras 已安装但无法导入,因为它说找不到 keras 模块
【发布时间】:2021-07-23 18:55:35
【问题描述】:
!pip install Keras
import Keras
print(Keras.__version__)
import tensorflow as tf
print(tf.__version__)

运行上述代码后,我在尝试使用 nlp 和深度学习解决分类问题时遇到此错误,这就是我尝试安装 tensorflow 和 keras 的原因。但它不断向我抛出错误。

 Requirement already satisfied: Keras in c:\users\hind\anaconda3\envs\toxic\lib\site-packages (2.4.3)
Requirement already satisfied: pyyaml in c:\users\hind\anaconda3\envs\toxic\lib\site-packages (from Keras) (5.4.1)
Requirement already satisfied: numpy>=1.9.1 in c:\users\hind\anaconda3\envs\toxic\lib\site-packages (from Keras) (1.19.5)
Requirement already satisfied: h5py in c:\users\hind\anaconda3\envs\toxic\lib\site-packages (from Keras) (3.1.0)
Requirement already satisfied: scipy>=0.14 in c:\users\hind\anaconda3\envs\toxic\lib\site-packages (from Keras) (1.6.2)
Requirement already satisfied: cached-property in c:\users\hind\anaconda3\envs\toxic\lib\site-packages (from h5py->Keras) (1.5.2)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-6-0a6f7852735b> in <module>
      1 get_ipython().system('pip install Keras')
----> 2 import Keras
      3 print(Keras.__version__)
      4 import tensorflow as tf
      5 print(tf.__version__)

ModuleNotFoundError: No module named 'Keras'

【问题讨论】:

  • 安装keras后有没有重启过内核?如果你在 jupyter notebook 中运行
  • @Kaveh 是的很多次
  • 你试过了吗? !pip3 install keras
  • @Kaveh 问题不在于安装,因为要求已经满足,它不知何故没有导入 keras,是的,我也试过了
  • 您的首字母大写。以小写形式使用。 import keras 不是 Keras

标签: python keras anaconda


【解决方案1】:

对于这个问题,这些是最常见的错误及其解决方案:

  • 你的机器上同时安装了python2和python3,python2使用pip,python3使用pip3,但是你安装的包版本错误。尝试使用!pip3 install keras
  • 确保在安装任何软件包后重新启动内核。
  • Python 区分大小写。确保你有正确的情况下的一切。它是 kerastensorflow,而不是 Keras 或 Tensoflow。
  • 如果您同时拥有 tensorflow 和 keras,取决于版本,可能会出现一些冲突,并且在执行 import keras 时会出错。请改用from tensorflow import keras

【讨论】:

  • 最后一招奏效了。 ` from tensorflow import kreas`.
【解决方案2】:

试试这个: !pip install keras 或 pip3 install keras

import keras
print(keras.__version__)

import tensorflow as tf
print(tf.__version__)

你的sn-p中的包名不正确

【讨论】:

  • 在执行上述 AttributeError 后出现此错误:模块 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
  • 试试这个:from tensorflow import keras
  • 你能在你的问题中粘贴上面的python版本和错误堆栈吗?
猜你喜欢
  • 2021-01-31
  • 2019-10-21
  • 2020-04-18
  • 1970-01-01
  • 2023-03-08
  • 2020-11-10
  • 2017-02-17
  • 1970-01-01
  • 2018-04-23
相关资源
最近更新 更多