【问题标题】:unable to import "from google.cloud import bigquery"无法导入“从 google.cloud 导入 bigquery”
【发布时间】:2021-05-06 14:01:19
【问题描述】:

我正在使用 python 开发 pipenv 环境,当我导入 bigquery 时它失败了:

from google.cloud import bigquery

返回:

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 信息:

  [[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"

【问题讨论】:

  • 你用的是什么版本的python? @ore​​n
  • 我使用的是 Python 3.7.10。通过 brew 安装。

标签: python google-bigquery pipenv pipenv-install


【解决方案1】:

为了使用这个库,你首先需要经过以下步骤:

为您的项目启用计费

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

启用 Google Cloud BigQuery API。

https://cloud.google.com/bigquery

设置身份验证。

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

如果您已经完成上述步骤:

尝试使用 pip3 命令而不是传统的 pip 升级 protobuf api,如下所示:

!pip3 install --upgrade protobuf

【讨论】:

  • 为此项目启用了计费和 Google Cloud BigQuery API。我以前多次为同一个项目使用相同的代码,并且在导入此包时从未出现此错误。我尝试上下更改 protobuf 版本,但仍然出现相同的错误。
  • 参考下面的链接,这可能会帮助您解决问题github.com/googleapis/python-bigquery/issues/…
【解决方案2】:

当您看到这样的错误时,它还表示 bigquery 版本不是您安装它的操作系统的正确版本。

我的操作系统版本(Ubuntu 16.0)和我的 bigquery 版本从 2.4.0 降级到 1.10.1 时遇到了类似的问题。问题已解决。

谢谢 巴杰什

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-21
    • 2018-11-23
    • 2021-03-12
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2021-01-16
    • 2019-05-20
    相关资源
    最近更新 更多