![](/img/trans.png)
[英]ModuleNotFoundError: No module named 'keras' Can't import 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__)
您的代碼段中的包名稱不正確
對於此問題,以下是最常見的錯誤及其解決方案:
pip
, python3 使用pip3
,但是你安裝了錯誤版本的包。 嘗試使用!pip3 install keras
keras
和tensorflow
,而不是 Keras 或 Tensoflow。import keras
會出錯。 改用from tensorflow import keras
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.