import keras: TypeError: __new__() got an unexpected keyword argument 'file'

Keras 与 Tensorflow 版本不兼容导致。

Keras 版本:2.1.5

$ pip show keras
Name: Keras
Version: 2.1.5
Summary: Deep Learning for humans
Home-page: https://github.com/keras-team/keras
Author: Francois Chollet
Author-email: [email protected]
License: MIT
Location: /anaconda3/lib/python3.6/site-packages
Requires: numpy, pyyaml, scipy, six

目前,pip 安装的最新的 Tensorflow 版本是 1.7.0,不兼容。

解决办法:

  • conda 使用 Tsinghua 镜像源:https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  • conda 能安装较低版本的 Tensorflow

Tensorflow 版本:1.1.0

$ pip show tensorflow
Name: tensorflow
Version: 1.1.0
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /anaconda3/lib/python3.6/site-packages
Requires: wheel, six, numpy, protobuf, werkzeug

输出:

Using TensorFlow backend. # 使用 Tensorflow 作为后台搭建网络

你可能感兴趣的:(import keras: TypeError: __new__() got an unexpected keyword argument 'file')