mehowl
mehowl

Reputation: 41

google cloud bigquery import failing because "ImportError: cannot import name 'client_pb2' from 'google.api'"

I'm trying to import bigquery from google.cloud, but it's failing because there's a missing dependency. I'm using Python 3.7.1.

Here is the error I'm getting:

Python 3.7.1 (default, Dec 14 2018, 13:28:58) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> from google.cloud import bigquery
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda3/lib/python3.7/site-packages/google/cloud/bigquery/__init__.py", line 35, in <module>
    from google.cloud.bigquery.client import Client
  File "/anaconda3/lib/python3.7/site-packages/google/cloud/bigquery/client.py", line 53, in <module>
    from google.cloud.bigquery.dataset import Dataset
  File "/anaconda3/lib/python3.7/site-packages/google/cloud/bigquery/dataset.py", line 24, in <module>
    from google.cloud.bigquery.model import ModelReference
  File "/anaconda3/lib/python3.7/site-packages/google/cloud/bigquery/model.py", line 27, in <module>
    from google.cloud.bigquery_v2 import types
  File "/anaconda3/lib/python3.7/site-packages/google/cloud/bigquery_v2/__init__.py", line 23, in <module>
    from google.cloud.bigquery_v2 import types
  File "/anaconda3/lib/python3.7/site-packages/google/cloud/bigquery_v2/types.py", line 23, in <module>
    from google.cloud.bigquery_v2.proto import model_pb2
  File "/anaconda3/lib/python3.7/site-packages/google/cloud/bigquery_v2/proto/model_pb2.py", line 28, in <module>
    from google.api import client_pb2 as google_dot_api_dot_client__pb2
ImportError: cannot import name 'client_pb2' from 'google.api' (/anaconda3/lib/python3.7/site-packages/google/api/__init__.py)

I've tried upgrading, and uninstalling and reinstalling the "google-cloud-bigquery" and "google-api-python-client" libraries, but this error continues to occur.

I'm not sure how to resolve this error or how to debug it further. I thought it may have been my version of the package, but I haven't been able to replicate this issue on other computers. Is it possible this is occurring because of my version of Python, or because it's installed through Anaconda?

Edit: https://github.com/googleapis/google-cloud-python/issues/8674

Solution is there - upgrade googleapis-common-protos

Upvotes: 4

Views: 6331

Answers (1)

Enrique Zetina
Enrique Zetina

Reputation: 835

As you mentioned in your post the solution is to update the module googleapis-common-protos using:

pip install --upgrade googleapis-common-protos

Common Protos are common dependencies throughout the Google API ecosystem, and which are made available for use as dependencies elsewhere as BigQuery.

Upvotes: 2

Related Questions