文件“C:\Python3832\lib\苹果公司,第411行

2024-04-27 13:41:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在构建一个python3.8脚本,将googlecloud存储桶中的csv文件加载到googlecloud项目的一个数据集中的给定表中。命令块是:

commandtobq = "bq load --source_format=CSV --skip_leading_rows=1 --field_delimiter=\"^|\" "
commandtobq += " " + gcptrendtable
commandtobq += " " + gsincomingfolder + filetrendoutputname
commandtobq += " \"" + filetrendschema + "\""
print(commandtobq)
os.system(commandtobq)  

这将生成以下命令:

bq load --source_format=CSV --skip_leading_rows=1 --field_delimiter="^|"  AvgPDHrsAssoc.avgpdhrsassoc_trend_x 
gs://thd_tr_incoming/AvgPDHrsAssoc-Retail-Trend-GCP-Output-2019-10-23.csv 
"P:\Delivery Team\Execution Reports\Reports-Python\THD-TR-AvgPDHrsAssoc-Retail\SQLs\AvgPDHrsAssoc-Retail-LSR-Extract-v01-Trend-Schema.json"

将此命令复制/粘贴到命令提示窗口中时,它将完美执行。当我使用os.system(commandtobq)通过python执行它时,它会失败,并出现以下错误:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\..\bin\bootstrapping\bq.py", line 10, in <module>
    import os
  File "C:\Python38-32\lib\os.py", line 411
    yield from walk(new_path, topdown, onerror, followlinks)
             ^
SyntaxError: invalid syntax

如何解决此错误?请注意,我之前在机器上安装了python2.7和3.6,但是为了新安装3.8,我将这两个版本都删除了。你知道吗

任何想法都会有帮助!谢谢您!你知道吗

添加了以下内容: 我使用Eclipse.3a版本(4.7.3a)作为IDE,以防影响问题或解决方案


Tags: csv命令formatsourceosloadrowsbq
1条回答
网友
1楼 · 发布于 2024-04-27 13:41:05

有你的程序吗

import sys
print(sys.executable)
print(sys.version)

看起来您是添加yield from之前的Python版本,而不是使用yield from的库的较新版本。你知道吗

计算您拥有的Python*.exe文件数。你没有使用生活在C:\Python38-32的那个。你知道吗

用于Windows的google-cloud-sdk可以选择拥有自己的绑定python2.7。安装3.8可能会导致此Python尝试使用3.8附带的库。你知道吗

相关问题 更多 >