首页 > 解决方案 > 无法使用 Anaconda 安装 Python 的 Keras

问题描述

我想在 Python ( https://keras.io/ ) 中安装用于机器学习的 libaray Keras。我使用 Anaconda(作为管理员)并尝试了以下命令。

(base) C:\Users\wi9632>conda install keras

这是带有错误消息的输出:

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: -
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - keras -> python[version='>=3.5,<3.6.0a0|>=3.6,<3.7.0a0']

Your python: python=3.8.5

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

你能告诉我为了安装 Keras 我必须做什么吗?如果我理解正确,我的 Python 环境的版本是新的吗?我会很感激每一条评论。

没有人知道我能做什么吗?我会很高兴的。

更新:我使用以下命令进行了尝试:

conda install -c conda-forge keras (请参阅https://anaconda.org/conda-forge/keras),我尝试使用 Anaconda 的 GUI 安装软件包。两者都产生了相同的错误消息。

标签: pythonkerasanaconda

解决方案


问题似乎在于 withconda而不是 with keras,请参见此处。使用pip代替conda可能会解决您的问题。

但是,我不鼓励使用keras,因为现在使用tf.keras是使用 Keras 的推荐方式,请参见此处

Keras 2.3.0 是支持 TensorFlow 2.0 的多后端 Keras 的第一个版本。它保持与 TensorFlow 1.14、1.13 以及 Theano 和 CNTK 的兼容性。

此版本使 API 与 TensorFlow 2.0 中的 tf.keras API 保持同步。但是请注意,它不支持大多数 TensorFlow 2.0 功能,尤其是急切执行。如果您需要这些功能,请使用 tf.keras。

这也是多后端 Keras 的最后一个主要版本。展望未来,我们建议用户考虑将他们的 Keras 代码切换到 TensorFlow 2.0 中的 tf.keras。

因此,如果对您有用,只需在您的代码中conda install tensorflow替换任何外观。这样就不需要单独安装了。kerastf.keraskeras


推荐阅读