从 google.cloud 导入 bigquery ModuleNotFoundError:没有名为“google”的模块

     2023-03-25     213

关键词:

【中文标题】从 google.cloud 导入 bigquery ModuleNotFoundError:没有名为“google”的模块【英文标题】:from google.cloud import bigquery ModuleNotFoundError: No module named 'google' 【发布时间】:2019-09-17 03:02:30 【问题描述】:

按照基本的 Google 云运行教程 (https://cloud.google.com/run/docs/quickstarts/build-and-deploy),

我一直在尝试部署到更复杂的东西但没有成功..

我的 app.py 以这些导入开始:

import os
import uuid
import requests
import json
from google.cloud import bigquery
from flask import Flask

但是当我尝试运行它时,我得到以下日志:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker 
    worker.init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process 
    super(ThreadWorker, self).init_process() 
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi() 
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi 
    self.callable = self.load()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load 
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp 
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app 
    __import__(module)
  File "/app/app.py", line 6, in <module> 
    from google.cloud import bigquery
ModuleNotFoundError: No module named 'google'

Dockerfile 看起来像这样:

# Use the official Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN pip install Flask gunicorn requests uuid google

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app

【问题讨论】:

【参考方案1】:

看起来要为 BigQuery 安装的正确 python 模块是 google-cloud-bigquery

RUN pip install Flask gunicorn requests uuid google-cloud-bigquery

【讨论】:

ImportError:无法从“google.cloud”(未知位置)导入名称“bigquery”

】ImportError:无法从“google.cloud”(未知位置)导入名称“bigquery”【英文标题】:ImportError:cannotimportname\'bigquery\'from\'google.cloud\'(unknownlocation)【发布时间】:2021-03-2116:55:31【问题描述】:我正在尝试部署一个云函数,它在从google... 查看详情

Google Cloud Function - ImportError:无法从“google.cloud”(未知位置)导入名称“pubsub”

】GoogleCloudFunction-ImportError:无法从“google.cloud”(未知位置)导入名称“pubsub”【英文标题】:GoogleCloudFunction-ImportError:cannotimportname\'pubsub\'from\'google.cloud\'(unknownlocation)【发布时间】:2019-02-2608:49:40【问题描述】:我正在部署一... 查看详情

如何从 google.cloud 导入 bigquery 模块

】如何从google.cloud导入bigquery模块【英文标题】:howtoimportbigquerymodulefromgoogle.cloud【发布时间】:2020-08-0822:13:30【问题描述】:我对SQL很陌生,我被指示运行以下代码:fromgoogle.cloudimportbigquery但我似乎无法超越第一步-我不断收到... 查看详情

ImportError:无法从“google.cloud”导入名称“tasks_v2”

】ImportError:无法从“google.cloud”导入名称“tasks_v2”【英文标题】:ImportError:cannotimportname\'tasks_v2\'from\'google.cloud\'【发布时间】:2021-03-1217:24:03【问题描述】:我正在尝试使用此处GCP文档中提供的GoogleCloudTasks代码示例:https://cl... 查看详情

无法从“google.cloud”(未知位置)导入名称“dataproc_v1”

】无法从“google.cloud”(未知位置)导入名称“dataproc_v1”【英文标题】:cannotimportname\'dataproc_v1\'from\'google.cloud\'(unknownlocation)【发布时间】:2020-12-2910:40:48【问题描述】:尝试从计算机通过JupyterNotebook访问UsingDataproc,我使用pip... 查看详情

H2O-3 AI 无法将模型从 Google Cloud Storage 导入集群

】H2O-3AI无法将模型从GoogleCloudStorage导入集群【英文标题】:H2O-3AICannotImportModelfromGoogleCloudStoragetoCluster【发布时间】:2021-08-0304:28:03【问题描述】:过去几天我一直在尝试在GoogleH2OCluster上运行保存的H2O模型。我能够使用本指南部... 查看详情

google.cloud 导入存储:无法导入存储

】google.cloud导入存储:无法导入存储【英文标题】:google.cloudimportstorage:cannotimportstorage【发布时间】:2018-11-2305:30:14【问题描述】:我尝试按照我在此处找到的谷歌教程运行下面的代码:https://cloud.google.com/docs/authentication/productio... 查看详情

从 Cloud Function (python) 写入 Google Cloud Storage

】从CloudFunction(python)写入GoogleCloudStorage【英文标题】:WritetoGoogleCloudStoragefromCloudFunction(python)【发布时间】:2019-02-1410:14:56【问题描述】:我正在尝试从云功能中将文件上传到谷歌云存储。不过,我无法将云存储库导入到我的函... 查看详情

ImportError:没有名为 google.cloud 的模块

】ImportError:没有名为google.cloud的模块【英文标题】:ImportError:Nomodulenamedgoogle.cloud【发布时间】:2017-11-0721:54:48【问题描述】:我无法导入google.cloud.speechfromgoogle.cloudimportspeech我已经安装了它:pipinstall--upgradegoogle-cloud-speech-tdir-na... 查看详情

google cloud pubsub ImportError:无法导入名称类型

】googlecloudpubsubImportError:无法导入名称类型【英文标题】:googlecloudpubsubImportError:cannotimportnametypes【发布时间】:2018-12-1107:14:05【问题描述】:我使用google-cloud-pubsub为标准环境在python上为Googleappengine编写了一个小程序。我收到... 查看详情

Google Cloud Messaging Bridging Header 导入失败

】GoogleCloudMessagingBridgingHeader导入失败【英文标题】:GoogleCloudMessagingBridgingHeaderimportfails【发布时间】:2015-08-2606:54:57【问题描述】:我正在我的SwiftiOS应用中实现GoogleCloudMessaging。我正在关注本指南:https://developers.google.com/cloud-m... 查看详情

ImportError:无法导入名称 pubsub_v1

..._v1【发布时间】:2018-04-1105:22:24【问题描述】:我需要从google.cloud模块导入Pubsub_v1和bigquery。我已经安装了它,pipfreeze显示如下:gapic-google-cloud-pubsub-v1==0.15.4google-cloud-bigque 查看详情

__init__.py 中的 google.cloud 命名空间导入错误

】__init__.py中的google.cloud命名空间导入错误【英文标题】:google.cloudnamespaceimporterrorin__init__.py【发布时间】:2020-07-0214:27:38【问题描述】:我已经阅读了至少十几个不同的***问题,这些问题都提出了相同的基本问题并且具有相同... 查看详情

Google Cloud Tasks ImportError:无法导入名称“resource_pb2”

】GoogleCloudTasksImportError:无法导入名称“resource_pb2”【英文标题】:GoogleCloudTasksImportError:cannotimportname\'resource_pb2\'【发布时间】:2019-10-1508:24:06【问题描述】:尝试使用google提供的python示例代码将任务添加到GoogleCloudTasks队列。... 查看详情

如何将公共数据集导入 Google Cloud Bucket

】如何将公共数据集导入GoogleCloudBucket【英文标题】:HowtoimportpublicdatasetintoGoogleCloudBucket【发布时间】:2019-12-1805:20:03【问题描述】:我将处理一个包含美国311电话信息的数据集。此数据集在BigQuery中公开可用。我想直接将它复... 查看详情

从 Google Cloud 内部 IP 调用 Google Cloud 存储桶

】从GoogleCloud内部IP调用GoogleCloud存储桶【英文标题】:CallingGoogleCloudBucketsfromGoogleCloudinternalIP【发布时间】:2020-03-1611:12:41【问题描述】:我在GoogleCloud上有一个包含文件(my-large-file.zip)的存储桶(my-bucket-name)。我创建了一个带有GET... 查看详情

从 Google Cloud Function (Python) 将新文件写入 Google Cloud Storage 存储桶

】从GoogleCloudFunction(Python)将新文件写入GoogleCloudStorage存储桶【英文标题】:WritinganewfiletoaGoogleCloudStoragebucketfromaGoogleCloudFunction(Python)【发布时间】:2020-05-0502:01:47【问题描述】:我正在尝试从PythonGoogleCloudFunction内部将新文件(而... 查看详情

从 Cloud Run on Google Cloud 访问 Cloud SQL

】从CloudRunonGoogleCloud访问CloudSQL【英文标题】:AccessingCloudSQLfromCloudRunonGoogleCloud【发布时间】:2020-11-0501:30:18【问题描述】:我有一个通过SQLAlchemy访问CloudSQL实例的CloudRun服务。但是,在CloudRun的日志中,我看到了CloudSQLconnectionfai... 查看详情