TensorFlow1.0 运行报错 AttributeError: type object 'NewBase' has no attribute 'is_abstract'

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hellonlp/article/details/66582767

博客地址:http://blog.csdn.net/wangxinginnlp/article/details/66582767


安装TF后,import tensorflow报错:

I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 124, in <module>
    from tensorflow.python.platform import test
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/test.py", line 36, in <module>
    from tensorflow.python.framework import test_util as _test_util
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/test_util.py", line 43, in <module>
    from tensorflow.python.platform import googletest
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/googletest.py", line 33, in <module>
    from tensorflow.python.platform import benchmark  # pylint: disable=unused-import
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/benchmark.py", line 117, in <module>
    class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)):
  File "/usr/lib/python2.7/dist-packages/six.py", line 617, in with_metaclass
    return meta("NewBase", bases, {})
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/benchmark.py", line 112, in __new__
    if not newclass.is_abstract():
AttributeError: type object 'NewBase' has no attribute 'is_abstract'

网上都说是six版本没有更新的原因。

pip six 发现six 版本1.5.4

pip install six --upgrade后six版本1.10.0

但是错误依然存在。

找了好久各种方法都试过没成功,找打这个才有效果:https://github.com/tensorflow/tensorflow/issues/1965

1. 

Looking specifically at the NewBase issue: please tell me the exact version of python and six that you are using.

import six 

print(six.__version__)

(我的竟然还是输出1.5.4)


2.

*Here is the thing: I have installed "six-v1.10.0" by pip upgrading, but when I open the python and print the version of six, it still says "1.5.2".


*I have figured out how to upgrade the package "six" properly.
The default location of "pip install" in my computer is "/usr/local/lib/python2.7/dist-packages". So when I upgrade "six", it is the file in "/usr/local/lib/python2.7/dist-packages" that is upgraded.
However, when we import some package in Python, another location "/usr/lib/python2.7/dist-packages" is searched first, while the file "six.py" in this location has never been upgraded.
So what we need to do is to modify the default location of "pip install" from "/usr/local/lib/python2.7/dist-packages" to "/usr/lib/python2.7/dist-packages"; then we can upgrade the right "six.py".
To modify the default location, we can make a new file "/etc/pip.conf", and type the following into this file:
"
[global]
target=/usr/lib/python2.7/dist-packages
".
Now you can upgrade the package "six" properly.
To avoid some unknown error, you may want to change the default location back to "/usr/local/lib/python2.7/dist-packages" after upgrading "six".


解决办法就是:

step1. 新建一个文件/etc/pip.conf并输入

[global]
target=/usr/lib/python2.7/dist-packages

step2. 更新six






猜你喜欢

转载自blog.csdn.net/hellonlp/article/details/66582767
今日推荐