我试图安装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 kerasRequirement 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 官方仅在Windows上支持Python 3.5.x版本。对于Python 2,你需要将后端切换到Theano。你可以在C:\Users\username\.keras\keras.json
中将Keras后端更改为Theano。另请查看此文档。
如果你想在脚本中切换到另一个Keras后端,你也可以使用以下代码:
import osos.environ['KERAS_BACKEND'] = "theano" #or "tensorflow"import keras