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 安装 keras 或 pip3 安装 keras
import keras
print(keras.__version__)
import tensorflow as tf
print(tf.__version__)
您的代码段中的包名称不正确
对于此问题,这些是最常见的错误及其解决方案:
- python2和python3都安装在你的机器上,python2使用
pip
,python3使用pip3
,但是你安装错误版本的软件包。尝试使用 !pip3 install keras
- 确保在安装任何软件包后重新启动内核。
- Python 区分大小写。确保所有东西都装在正确的大小写中。它是
keras
和 tensorflow
,不是 Keras 或 Tensoflow。
- 如果您同时拥有 tensorflow 和 keras,取决于版本,可能会发生一些冲突,并且在执行时会出错
import keras
。请改用 from tensorflow import keras
.
!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 安装 keras 或 pip3 安装 keras
import keras
print(keras.__version__)
import tensorflow as tf
print(tf.__version__)
您的代码段中的包名称不正确
对于此问题,这些是最常见的错误及其解决方案:
- python2和python3都安装在你的机器上,python2使用
pip
,python3使用pip3
,但是你安装错误版本的软件包。尝试使用!pip3 install keras
- 确保在安装任何软件包后重新启动内核。
- Python 区分大小写。确保所有东西都装在正确的大小写中。它是
keras
和tensorflow
,不是 Keras 或 Tensoflow。 - 如果您同时拥有 tensorflow 和 keras,取决于版本,可能会发生一些冲突,并且在执行时会出错
import keras
。请改用from tensorflow import keras
.