从 google.cloud 导入 bigquery 模块未发现错误:没有名为 'google' 的模块



遵循基本的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

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

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

最新更新