使用python脚本从gcs bucket读取文件时出现的问题

2024-04-28 16:08:04 发布

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

我试图打开gcs bucket中的csv文件来读取内容并在BigQuery中相应地处理数据。我能列出csv的存在在桶,但不能打开它。我的代码如下:

with cloudstorage.open(bucket_name/gs_file,"r+") as csvFile:
     reader = csv.reader(iter(csvFile.readline,''), delimiter = '|')
     csvfilearray = next(reader)
     print (csvfilearray)

获取以下错误:

NameError: name 'cloudstorage' is not defined

导入的云存储如下:

^{pr2}$

并再次尝试使用gcs.open,但仍然错误:

File "./GCS_Connection_Test.py", line 10, in <module>
    import cloudstorage as gcs
ImportError: No module named cloudstorage

有谁能帮忙打开GCS上的文件进行处理吗。在


Tags: 文件csvcsvfilename内容bucketas错误
1条回答
网友
1楼 · 发布于 2024-04-28 16:08:04

根据您的app.yaml文件,您处于灵活的环境中。在

您使用了GoogleAppEngineCloudStorageClient,这是一个标准的环境库(就像appengine-gcs-client),您需要使用google-cloud-storage库,请参阅Using Cloud Storage指南中的Edit project configuration and install dependencies部分,这是您需要遵循的。在

您还遵循了安装库的标准环境说明,您需要使用灵活的环境说明,请参见Using Python Libraries。在

一般注意:在doc页面url中查找docs/flexiblevsdocs/standard字符串,以区分它们(或者在文档左侧导航栏顶部附近显示的环境类型,您可能需要向上滚动才能看到它)

相关问题 更多 >