Keras 包安装

Keras package installation

我正在尝试安装 Keras 包以使用机器学习工具。 不幸的是我无法这样做。我安装了theano。我在 python 3.5 的单独环境中安装了 tensorflow,但我正在尝试为此使用 python 2.7。是这个问题吗?

C:\Users\User>pip install tensorflow   
Collecting tensorflow   
  Could not find a version that satisfies the requirement tensorflow (from versions: )   
No matching distribution found for tensorflow   

C:\Users\User>pip install keras
Requirement already satisfied: keras in c:\users\user\anaconda2\lib\site-packages   
Requirement already satisfied: theano in c:\users\user\anaconda2\lib\site-packages (from keras)   
Requirement already satisfied: pyyaml in c:\users\user\anaconda2\lib\site-packages (from keras)   
Requirement already satisfied: six in c:\users\user\anaconda2\lib\site-packages (from keras)   
Requirement already satisfied: numpy>=1.9.1 in c:\users\user\anaconda2\lib\site-packages (from theano->keras)   
Requirement already satisfied: scipy>=0.14 in c:\users\user\anaconda2\lib\site-packages (from theano->keras)   

我仍然遇到导入错误,说当我尝试导入 keras 时找不到 tensorflow 后端

Tensorflow officially only supports Python 3.5.x on Windows. For python 2 you need to switch your backend to Theano. You can change the Keras backend to Theano in C:\Users\username\.keras\keras.json. Also check this 文档。

如果你想在脚本中切换到另一个keras后端你也可以使用下面的代码:

import os
os.environ['KERAS_BACKEND'] = "theano" #or "tensorflow"
import keras