【问题标题】:Trouble with Installing Keras安装 Keras 遇到问题
【发布时间】:2020-10-11 16:10:49
【问题描述】:

我已经尝试了几件事,但在尝试将 keras 安装到 Python 时遇到了很多困难。

  1. 首先,我尝试使用以下命令将其导入到我的 Jupyter Notebook 中:
from keras.models import Sequential
from keras.layers import Dense

导致以下错误:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-17-b9e2c8277ae4> in <module>
----> 1 from keras.models import Sequential
      2 from keras.layers import Dense

ModuleNotFoundError: No module named 'keras'
  1. 然后,我尝试导入 tensorflow。
from tensorflow.keras.models import Sequential 
from tensorflow.keras.layers import Dense,Dropout,Activation, Flatten, Conv2D, MaxPooling2D 

这也不起作用,因为我收到了与以前类似的错误。

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-18-9d4e366b5092> in <module>
----> 1 from tensorflow.keras.models import Sequential #used for model building
      2 from tensorflow.keras.layers import Dense,Dropout,Activation, Flatten, Conv2D, MaxPooling2D #used for model building

ModuleNotFoundError: No module named 'tensorflow'
  1. 我终于尝试通过 Anaconda 使用终端。这也失败了。
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

我有 Python 3.8,但显然 keras 需要 python[version='&gt;=2.7,&lt;2.8.0a0|&gt;=3.5,&lt;3.6.0a0|&gt;=3.6,&lt;3.7.0a0']。如何导入 keras?

【问题讨论】:

  • 我不是专家,但根据您的最后一段,keras 似乎不适用于 python 3.8。还是我误解了?
  • @Maxijazz - 是的,看起来是这样,我应该以某种方式恢复我的 Python 版本吗????
  • 我不认为错误是由于版本。否则你会得到 UnsatisfiableError: The following specification was incompatible with the existing python installation in your environment 错误
  • 我能做些什么来解决这个问题?我很迷茫。 @PranjalDoshi
  • 从日志看来,keras 和 tensorflow 没有安装。你确定它们已经安装了吗?

标签: python tensorflow keras import anaconda


【解决方案1】:

无论出于何种原因,kerastensorflow 都不能很好地与 Python 3.8 配合使用。我会尝试恢复到 Python 3.7。

【讨论】:

  • 不,这不是真的,问题出在 Anaconda 中,它没有为 Python 3.8 打包 Keras 和 TensorFlow (v 2.2),这是他们这边的打包错误。 Keras 特别适用于 Python 3.8
猜你喜欢
  • 2019-08-21
  • 2020-11-11
  • 2014-09-11
  • 2013-12-24
  • 2020-02-27
  • 2018-02-25
  • 2011-06-06
  • 2021-04-14
  • 2016-03-23
相关资源
最近更新 更多