Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Vision's Python Client Quickstart throws TypeError: bases must be types

I am trying to run the quickstart from Google's Vision python library locally. However, when I run python3 quickstart.py I get the following error:

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

What I know is:

  • This doesn't happen when I run quickstart in the Google CloudShell
  • I am using the right creds, GOOGLE_APPLICATION_CREDENTIALS=key.json
  • I am using python 3.9.12 locally
  • I installed requirements.txt using pip3 (google-cloud-vision==2.7.2)
  • python3 and pip3 are both in the right /anaconda3/envs/vision path.
  • My OS is macOS Monterey 12.4

I am not sure at what point in this stack trace that the error is occurring, or how to fix it.

like image 859
William Torkington Avatar asked Oct 20 '25 07:10

William Torkington


1 Answers

According to @DazWilkin's comment, downgrade the protobuf package as follows.

pip uninstall protobuf
pip install protobuf==3.20.1

It worked just fine for me. tensorflow and protobuf versions were incompatible in my case.

like image 183
Hadij Avatar answered Oct 21 '25 22:10

Hadij



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!