Keras包安装

时间:2017-07-10 15:41:51

标签: python machine-learning neural-network keras theano

我正在尝试安装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后端

1 个答案:

答案 0 :(得分:0)

Tensorflow officially仅支持Windows上的Python 3.5.x.对于python 2,您需要将后端切换到Theano。您可以在C:\Users\username\.keras\keras.json中将Keras后端更改为Theano。另请查看this文档。

如果您想在脚本中切换到另一个keras后端,您还可以使用以下代码:

import os
os.environ['KERAS_BACKEND'] = "theano" #or "tensorflow"
import keras
相关问题