unable to import "from google.cloud import bigquery"

2.2k views Asked by At

I am working on a pipenv environment with python and when I import bigquery it fails:

from google.cloud import bigquery

returns:

Traceback (most recent call last):
File "/Users/orennieberg/Documents/git/guestybot/main.py", line 1, in <module>
from google.cloud import bigquery
File "/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/__init__.py", line 35, in 
<module>
from google.cloud.bigquery.client import Client
File "/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/client.py", line 56, in 
<module>
from google.cloud.bigquery import _pandas_helpers
File "/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/_pandas_helpers.py", line 
36, in <module>
from google.cloud.bigquery import schema
File "/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/schema.py", line 19, in 
<module>
from google.cloud.bigquery_v2 import types
File "/usr/local/lib/python3.7/site-packages/google/cloud/bigquery_v2/__init__.py", line 19, 
in <module>
from .types.encryption_config import EncryptionConfiguration
File "/usr/local/lib/python3.7/site-packages/google/cloud/bigquery_v2/types/__init__.py", 
line 18, in <module>
from .encryption_config import EncryptionConfiguration
File "/usr/local/lib/python3.7/site- 
packages/google/cloud/bigquery_v2/types/encryption_config.py", line 29, in <module>
class EncryptionConfiguration(proto.Message):
File "/usr/local/lib/python3.7/site-packages/proto/message.py", line 214, in __new__
field=[i.descriptor for i in fields],
File "/usr/local/lib/python3.7/site-packages/proto/message.py", line 214, in <listcomp>
field=[i.descriptor for i in fields],
File "/usr/local/lib/python3.7/site-packages/proto/fields.py", line 111, in descriptor
proto3_optional=self.optional,
ValueError: Protocol message FieldDescriptorProto has no "proto3_optional" field.

 Process finished with exit code 1

Pipfile info:

  [[source]]
  name = "pypi"
  url = "https://pypi.org/simple"
  verify_ssl = true

  [dev-packages]

  [packages]
  spacy = "==2.2.3"
  pandas = "==0.25.3"
  pandas-gbq = "==0.14.1"
  numpy = "==1.18.1"
  Flask = "==1.1.1"
  blis = "==0.4.1"
  cachetools = "==4.0.0"
  catalogue = "==1.0.0"
  certifi = "==2019.11.28"
  chardet = "==3.0.4"
  click = "==7.0"
  cymem = "==2.0.3"
  six = "==1.15.0"
  google-api-core = "==1.23.0"
  google-api-python-client = "==1.12.8"
  google-auth = "==1.21.1"
  google-auth-httplib2 = "==0.1.0"
  google-auth-oauthlib = "==0.4.4"
  google-cloud = "==0.34.0"
  google-cloud-bigquery = "==2.10.0"
  google-cloud-bigquery-storage = "==2.4.0"
  google-cloud-core = "==1.4.1"
  google-cloud-storage = "==1.30.0"
  google-crc32c = "==1.1.2"
  google-pasta = "==0.1.8"
  google-resumable-media = "==0.6.0"
  googleapis-common-protos = "==1.51.0"
  idna = "==2.9"
  importlib-metadata = "==1.5.0"
  itsdangerous = "==1.1.0"
  murmurhash = "==1.0.2"
  plac = "==1.1.3"
  preshed = "==3.0.2"
  pyasn1-modules = "==0.2.8"
  pyasn1 = "==0.4.8"
  pybind11 = "==2.4.3"
  python-dateutil = "==2.8.1"
  pytz = "==2019.3"
  requests = "==2.23.0"
  rsa = "==4.0"
  srsly = "==1.0.2"
  thinc = "==7.3.1"
  tqdm = "==4.43.0"
  urllib3 = "==1.25.8"
  wasabi = "==0.6.0"
  zipp = "==3.1.0"
  Jinja2 = "==2.11.1"
  MarkupSafe = "==1.1.1"
  Werkzeug = "==1.0.0"
  keras = "==2.2.4"
  tensorflow = "==1.14.0"
  gunicorn = "*"
  textblob = "==0.15.3"
  nltk = "==3.4"
  torch = "==1.6"
  torchtext = "==0.6.0"
  langdetect = "==1.0.7"
  protobuf = "==3.15.8"

  [requires]
  python_version = "3.7"
2

There are 2 answers

2
Priyank Gupta On

In Order to use this library, you first need to go through the following steps:

Enable billing for your project

https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project

Enable the Google Cloud BigQuery API.

https://cloud.google.com/bigquery

Setup Authentication.

https://googleapis.dev/python/google-api-core/latest/auth.html

If you are already done with above steps :

Try upgrading the protobuf api with pip3 command instead of the conventional pip as thus:

!pip3 install --upgrade protobuf

0
Bhajesh Bharathan On

When you see the error like this, it also says that the bigquery version is not the right version for the OS where you installed it.

I had similar issue in my OS version (Ubuntu 16.0) and when I degraded my bigquery version from 2.4.0 to 1.10.1. The issue resolved.

Thanks Bhajesh