简体   繁体   English

无法导入“从 google.cloud 导入 bigquery”

[英]unable to import "from google.cloud import bigquery"

I am working on a pipenv environment with python and when I import bigquery it fails:我正在使用 python 处理 pipenv 环境,当我导入 bigquery 时它失败:

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"

In Order to use this library, you first need to go through the following steps:为了使用这个库,您首先需要通过以下步骤 go:

Enable billing for your project为您的项目启用计费

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

Enable the Google Cloud BigQuery API.启用 Google Cloud BigQuery API。

https://cloud.google.com/bigquery https://cloud.google.com/bigquery

Setup Authentication.设置身份验证。

https://googleapis.dev/python/google-api-core/latest/auth.html 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 命令而不是传统的 pip 升级 protobuf api,如下所示:

!pip3 install --upgrade protobuf !pip3 install --upgrade protobuf

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.当您看到这样的错误时,它还表示 bigquery 版本不是您安装它的操作系统的正确版本。

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.我在我的操作系统版本(Ubuntu 16.0)中遇到了类似的问题,当我将我的 bigquery 版本从 2.4.0 降级到 1.10.1 时。 The issue resolved.问题解决了。

Thanks Bhajesh谢谢巴杰什

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从google.cloud导入存储空间 - Unable to import storage from google.cloud 从google.cloud导入bigquery ModuleNotFoundError:没有名为“ google”的模块 - from google.cloud import bigquery ModuleNotFoundError: No module named 'google' 如何从 google.cloud 导入 bigquery 模块 - how to import bigquery module from google.cloud 导入错误:无法从“google.cloud”(未知位置)导入名称“bigquery_storage_v1beta1” - ImportError: cannot import name 'bigquery_storage_v1beta1' from 'google.cloud' (unknown location) ImportError:无法从“google.cloud”(未知位置)导入名称“bigquery” - ImportError: cannot import name 'bigquery' from 'google.cloud' (unknown location) 来自google.cloud导入语言ModuleNotFoundError:没有名为“ google.cloud”的模块 - from google.cloud import language ModuleNotFoundError: No module named 'google.cloud' 来自google.cloud导入firestore ModuleNotFoundError:没有名为&#39;google&#39;的模块 - from google.cloud import firestore ModuleNotFoundError: No module named 'google' 无法从google.cloud导入数据存储 - Can't import Datastore from google.cloud google.cloud 导入存储:无法导入存储 - google.cloud import storage: cannot import storage 从 google.cloud 导入 monitoring_v3 导入错误:无法导入名称 monitoring_v3 - from google.cloud import monitoring_v3 ImportError: cannot import name monitoring_v3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM