gpt4 book ai didi

Python,属性错误: module 'google.cloud.bigquery' has no attribute 'Client' after cx_Freeze build

转载 作者:行者123 更新时间:2023-12-01 01:16:59 29 4
gpt4 key购买 nike

我正在尝试使用 cx_Freeze 创建脚本的可执行文件,该脚本从同一文件夹加载 .sql 查询,在 BigQuery DB 上执行它并返回检索到的数据的 .csv。

  This is what the 'conda list' command gives me:
google-api-core 1.1.0 py_0 conda-forge
google-auth 1.6.2 py_0 conda-forge
google-cloud-bigquery 1.8.1 py_0 conda-forge
google-cloud-core 0.28.1 py_0 conda-forge
google-resumable-media 0.3.1 py_0 conda-forge
googleapis-common-protos 1.5.5 py_0 conda-forge

脚本在第一行崩溃(脚本中指定了 KEY 和 PROJECT_ID,但出于安全原因未粘贴)

from google.cloud import bigquery
client = bigquery.Client.from_service_account_json(KEY, project=PROJECT_ID)

我的 cx_Freeze setup.py 如下所示:

from cx_Freeze import setup, Executable

setup(name='output_script', executables = [Executable("my_script.py")], version="1.0.0",
options={
"build exe":{"packages":["google.cloud.bigquery, google.cloud.bigquery.client"]}})

构建成功执行,但是当我在构建文件夹中运行 my_script.exe 时,出现以下错误:

Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "my_script.py", line 15, in <module>
File "my_script.py", line 7, in queryBigQ
AttributeError: module 'google.cloud.bigquery' has no attribute 'Client'

尝试重新安装和更新所有 Google 软件包,但没有成功。任何指示将不胜感激。

最佳答案

在卡住脚本之前您是否尝试成功运行脚本?

您的本地开发环境似乎缺少 bigquery 库。确保您创建了 virtualenvinstall bigquery library就在其中。

使用简单的脚本测试与 BigQuery 的连接:

from google.cloud import bigquery

client = bigquery.Client()

QUERY = (
'SELECT * FROM `[PROJECT_ID].[BQ_INSTANCE].[BQ_TABLE]`'
)
query_job = client.query(QUERY)
rows = query_job.result()

for row in rows:
print(row)

关于Python,属性错误: module 'google.cloud.bigquery' has no attribute 'Client' after cx_Freeze build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54240262/

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