tebsorflow 安装问题 import 的时候出问题


(tensorflow) jiaxuan@jiaxuan:~$ python
Python 2.7.17 (default, Feb 27 2021, 15:10:58) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jiaxuan/tensorflow/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/jiaxuan/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/home/jiaxuan/tensorflow/local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
    from google.protobuf import descriptor as _descriptor
  File "/usr/local/lib/python2.7/dist-packages/google/protobuf/descriptor.py", line 113
    class DescriptorBase(metaclass=DescriptorMetaclass):
                                  ^
SyntaxError: invalid syntax
>>> 
          

安装完后 一直不能用,查了很多,没有遇到同样问题的. python 版本2.7.14 pip 版本pip 20.3.4 from /home/jiaxuan/.local/lib/python2.7/site-packages/pip (python 2.7)

【个人已解决】
【参考链接】

【问题原因】

img

【解决方法】

img

pip install protobuf==3.17.3

啊,我解决了,真的是pip install protobuf==3.17.3

这个报错的原因有很多,可以参考下这篇文章,希望对你有帮助:

进入你的/usr/local/lib/python2.7/dist-packages/google/protobuf/descriptor.py文件,把113行的等于号改成逗号,要英语的逗号,这应该是系统代码的问题

我也遇到了一样的问题,不过我的protobuf版本好像啥2.6.1,我也看了github issue下面的将3.18切换3.17,觉得好像不太靠谱...