gpt4 book ai didi

google-cloud-platform - 部署云功能时谷歌Bigquery导入错误

转载 作者:行者123 更新时间:2023-12-05 01:40:23 25 4
gpt4 key购买 nike

我有一个 python 云函数代码,它从 GCS 读取 .txt 文件,解析它并将行写入 bigquery。当我尝试从我的 MacOS 将此云功能部署到 Google 云时,出现以下错误

我已验证在我的 GCP 项目中启用了 Bigquery API。

gcloud 函数部署 sql_upload --runtime python37 --trigger-bucket test-bucket --entry-point load_sql

Deploying function (may take a while - up to 2 minutes)...failed.                                                                                                                                          
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: Code in file main.py can't be loaded.
Detailed stack trace: Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 305, in check_or_load_user_function
_function_handler.load_user_function()
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 184, in load_user_function
spec.loader.exec_module(main)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/user_code/main.py", line 24, in <module>
from google.cloud import bigquery
ImportError: cannot import name 'bigquery' from 'google.cloud' (unknown location)

最佳答案

Python 中的依赖项使用 pip 进行管理,并在名为 requirements.txt 的元数据文件中表示。此文件必须与包含函数代码的 main.py 文件位于同一目录中。

如果此代码在您的计算机上运行,​​则只需通过以下方式创建 requirements.txt 文件:

pip freeze > requirements.txt

否则,您必须先安装 bigquery 的依赖项,然后创建需求文件:

pip install --upgrade google-cloud-bigquery
pip freeze > requirements.txt

查看文档 https://cloud.google.com/functions/docs/writing/specifying-dependencies-python https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-install-python

关于google-cloud-platform - 部署云功能时谷歌Bigquery导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56762281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com