python2安装tensorflow报错class DescriptorBase(metaclass=DescriptorMetaclass),SyntaxError: invalid syntax

当python2安装tensorflow的时候,安装完成后,进行测试:

import tensorflow as tf

可能会提示:

Traceback (most recent call last):
  File "", line 1, in
  File "/home/zhaokai/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 28, in
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/zhaokai/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in
    from tensorflow.core.framework.graph_pb2 import *
  File "/home/zhaokai/.local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 7, in
    from google.protobuf import descriptor as _descriptor
  File "/home/zhaokai/.local/lib/python2.7/site-packages/google/protobuf/descriptor.py", line 113
    class DescriptorBase(metaclass=DescriptorMetaclass):
                                  ^
SyntaxError: invalid syntax

这个解决方法是重新安装 protobuf:

pip install protobuf==3.17.3

再次import tensorflow即可。

你可能感兴趣的:(神经网络笔记,tensorflow,人工智能,深度学习)