Google Vision 的 Python 客户端快速入门抛出 TypeError:基数必须是类型

Wil*_*ton 4 python google-api

我正在尝试在本地运行 Google Vision python 库的快速入门。但是,当我运行时,python3 quickstart.py出现以下错误:

Traceback (most recent call last):
  File "/Users/penguin/.../quickstart.py", line 53, in <module>
    print(run_quickstart())
  File "/Users/penguin/.../quickstart.py", line 25, in run_quickstart
    from google.cloud import vision
  File "/Users/pengui/anaconda3/envs/vision/lib/python3.9/site-packages/google/cloud/vision/__init__.py", line 18, in <module>
    from google.cloud.vision_v1.services.image_annotator.async_client import (
  File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/cloud/vision_v1/__init__.py", line 17, in <module>
    from google.cloud.vision_helpers.decorators import add_single_feature_methods
  File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/cloud/vision_helpers/__init__.py", line 16, in <module>
    import proto
  File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/proto/__init__.py", line 15, in <module>
    from .enums import Enum
  File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/proto/enums.py", line 17, in <module>
    from google.protobuf import descriptor_pb2
  File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/descriptor_pb2.py", line 5, in <module>
    from google.protobuf.internal import builder as _builder
  File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/internal/builder.py", line 42, in <module>
    from google.protobuf import reflection as _reflection
  File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/reflection.py", line 51, in <module>
    from google.protobuf import message_factory
  File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/message_factory.py", line 42, in <module>
    from google.protobuf.internal import api_implementation
  File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/internal/api_implementation.py", line 104, in <module>
    from google.protobuf.pyext import _message
TypeError: bases must be types
Run Code Online (Sandbox Code Playgroud)

我所知道的是:

  • 当我在 Google CloudShell 中运行快速启动时,不会发生这种情况
  • 我使用正确的凭据,GOOGLE_APPLICATION_CREDENTIALS=key.json
  • 我在本地使用 python 3.9.12
  • 我使用 pip3 安装了requirements.txt(google-cloud-vision==2.7.2)
  • python3和pip3都在正确的/anaconda3/envs/vision路径中。
  • 我的操作系统是 macOS Monterey 12.4

我不确定该堆栈跟踪中的哪个点发生错误,或者如何修复它。

Had*_*dij 6

根据@DazWilkin的评论,降级protobuf包如下。

pip uninstall protobuf
pip install protobuf==3.20.1
Run Code Online (Sandbox Code Playgroud)

它对我来说效果很好。tensorflow并且protobuf版本在我的情况下不兼容。