繁体   English   中英

Keras 已安装但无法导入,因为它说未找到 keras 模块

[英]Keras installed but can't import as it says keras module not found

!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'

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

import keras
print(keras.__version__)

import tensorflow as tf
print(tf.__version__)

您的代码段中的包名称不正确

对于此问题,以下是最常见的错误及其解决方案:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM