TensorFlow 升级后出现 ImportError: cannot import name 'abs'

TensorFlow 升级之后出现:

ImportError                               Traceback (most recent call last)
<ipython-input-1-64156d691fe5> in <module>()
----> 1 import tensorflow as tf

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\__init__.py in <module>()
     20 
     21 # pylint: disable=g-bad-import-order
---> 22 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     23 
     24 try:

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\__init__.py in <module>()
     79 # Bring in subpackages.
     80 from tensorflow.python import data
---> 81 from tensorflow.python import keras
     82 from tensorflow.python.feature_column import feature_column_lib as feature_column
     83 from tensorflow.python.layers import layers

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\__init__.py in <module>()
     22 from __future__ import print_function
     23 
---> 24 from tensorflow.python.keras import activations
     25 from tensorflow.python.keras import applications
     26 from tensorflow.python.keras import backend

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\activations\__init__.py in <module>()
     20 
     21 # Activation functions.
---> 22 from tensorflow.python.keras._impl.keras.activations import elu
     23 from tensorflow.python.keras._impl.keras.activations import hard_sigmoid
     24 from tensorflow.python.keras._impl.keras.activations import linear

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\_impl\keras\__init__.py in <module>()
     19 from __future__ import print_function
     20 
---> 21 from tensorflow.python.keras._impl.keras import activations
     22 from tensorflow.python.keras._impl.keras import applications
     23 from tensorflow.python.keras._impl.keras import backend

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\_impl\keras\activations.py in <module>()
     21 import six
     22 
---> 23 from tensorflow.python.keras._impl.keras import backend as K
     24 from tensorflow.python.keras._impl.keras.utils.generic_utils import deserialize_keras_object
     25 from tensorflow.python.layers.base import Layer

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\_impl\keras\backend.py in <module>()
     36 from tensorflow.python.framework import sparse_tensor
     37 from tensorflow.python.framework import tensor_util
---> 38 from tensorflow.python.layers import base as tf_base_layers
     39 from tensorflow.python.ops import array_ops
     40 from tensorflow.python.ops import clip_ops

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\layers\base.py in <module>()
     23 from tensorflow.python.framework import dtypes
     24 from tensorflow.python.framework import ops
---> 25 from tensorflow.python.keras.engine import base_layer
     26 from tensorflow.python.ops import variable_scope as vs
     27 from tensorflow.python.ops import variables as tf_variables

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\engine\__init__.py in <module>()
     21 # TODO (fchollet): Remove hourglass imports once external code is done importing
     22 # non-public APIs.
---> 23 from tensorflow.python.keras.engine.base_layer import InputSpec
     24 from tensorflow.python.keras.engine.base_layer import Layer
     25 from tensorflow.python.keras.engine.input_layer import Input

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in <module>()
     31 from tensorflow.python.framework import tensor_shape
     32 from tensorflow.python.framework import tensor_util
---> 33 from tensorflow.python.keras import backend
     34 from tensorflow.python.keras import constraints
     35 from tensorflow.python.keras import initializers

~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\backend\__init__.py in <module>()
     20 
     21 # pylint: disable=redefined-builtin
---> 22 from tensorflow.python.keras._impl.keras.backend import abs
     23 from tensorflow.python.keras._impl.keras.backend import all
     24 from tensorflow.python.keras._impl.keras.backend import any

ImportError: cannot import name 'abs'

在 GitHub 中按照如下方式进行卸载重装:

pip uninstall tensorflow tensorflow-gpu protobuf --yes
pip install --ignore-installed --upgrade --ignore-installed tensorflow-gpu

依然出现上述错误!!!

大家有遇到这种情况每?


Zach 2018-8-14 11:07:02

哈哈,打扰了!我解决了这个问题!

  1. 运行以下命令卸载 tensorflow 和 protocl
pip uninstall tensorflow tensorflow-gou protocol --yes
  1. 重新安装 tensorflow-gpu 1.9.0
pip install tensorflow-gpu==1.9.0

Zach 发表于 2018-8-14 13:55:17

最新的 1.10.0 版本学习了吗?


tf1998 发表于 2018-8-14 14:11:31

正在学习中……


Zach 2018-8-27 11:25

哈哈哈。我昨天也遇到了。卸了重装就好了。楼主优秀,自问自答~哈哈哈


Bingohong 发表于 2018-8-17 15:21:03

只是小菜小菜


Zach 2018-8-27 11:26

问题就是 tensorflow 和 tensorflow-gpu 版本不对应,重装或升级这俩即可。


浪 TF 发表于 2018-11-6 09:08:48