簡體   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