(搬运)最新版本tensorflow报错 ImportError: cannot import name 'abs'

解决Tensorflow最新版本导入时出现的'abs'错误,通过卸载protobuf和tensorflow相关模块,然后重新安装,让其自动匹配正确依赖。
摘要由CSDN通过智能技术生成
import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/junyi/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/__init__.py", line 28, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/junyi/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 83, in <module>
    from tensorflow.python import keras
  File "/home/junyi/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/keras/__init__.py", line 26, in <module>
    from tensorflow.python.keras import activations
  File "/home/junyi/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/keras/activations/__init__.py", line 22, in <module>
    from tensorflow.python.keras._impl.keras.activations import elu
  File "/home/junyi/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/__init__.py", line 21, in <module>
    from tensorflow.python.keras._impl.keras import activations
  File "/home/junyi/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/activations.py", line 23, in <module>
    from tensorflow.python.keras._impl.keras import backend as K
  File "/home/junyi/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/backend.py", line 37, in <module>
    from tensorflow.python.layers import base as tf_base_layers
  File "/home/junyi/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 25, in <module>
    from tensorflow.python.keras import backend
  File "/home/junyi/anaconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/keras/backend/__init__.py", line 22, in <module>
    from tensorflow.python.keras._impl.keras.backend import abs
ImportError: cannot import name 'abs'

解决方案,参考github
先卸载protobuf, tensorflow, tensorflow-gpu

pip uninstall tensorflow tensorflow-gpu protobuf

再重新安装tensorflow-gpu,会自动选择正确的依赖(我用的是ZJU源,-i 后面的可以去掉)

pip install tensorflow-gpu==1.14 -i https://mirrors.zju.edu.cn/pypi/web/simple
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值