通过python脚本从gcs bucket读取文件时出现问题

通过python脚本从gcs bucket读取文件时出现问题,python,google-app-engine,google-cloud-storage,Python,Google App Engine,Google Cloud Storage,我试图打开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 (c

我试图打开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)
import cloudstorage as gcs
获取以下错误:

NameError:未定义名称“cloudstorage”

导入的cloudstorage如下所示:

with cloudstorage.open(bucket_name/gs_file,"r+") as csvFile:
     reader = csv.reader(iter(csvFile.readline,''), delimiter = '|')
     csvfilearray = next(reader)
     print (csvfilearray)
import cloudstorage as gcs
并尝试使用
gcs。再次打开
,但仍有错误:

File "./GCS_Connection_Test.py", line 10, in <module>
    import cloudstorage as gcs
ImportError: No module named cloudstorage
文件“/GCS\u Connection\u Test.py”,第10行,在
将cloudstorage导入为gcs
ImportError:没有名为cloudstorage的模块

请任何人帮助打开GCS上的文件进行处理

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

您使用了
GoogleAppEngineCloudStorageClient
,这是一个标准的环境库(正如
appengine gcs client
),您需要使用
google云存储
库,请参阅指南中的一节,这是您需要遵循的

您还遵循了安装库的标准环境说明,需要使用灵活的环境说明,请参阅


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

是否安装了库?或者,如果您在GAE上,根据从google vm实例执行python代码来匹配导入的lib,我能够获取特定bucket下的对象列表。因此,似乎google cloud storage lib安装在那里。无法打开文件进行处理。我在下面的导入代码“from google.cloud import storage”storage\u client=storage.client()中编写了导入代码,并尝试使用“pip install GoogleAppEngineCloudStorageClient”进行安装。仍然出现如下错误:将cloudstorage作为gcs文件导入/usr/local/lib/python2.7/dist packages/cloudstorage/u init\uu.py”,第20行,在from.api_utils import RetryParams文件“/usr/local/lib/python2.7/dist packages/cloudstorage/api_utils.py”的第45行中,在from google.appengine.api import app_identity importorror:没有名为appengine.api的模块请帮助,需要做些什么来解决这是不是GAE app?如果是,您需要安装在应用程序中的第2个库(不在系统上),否则您需要安装在系统上的第1个库。首先,非常感谢你回答我的问题。我是谷歌云的新手,有点沉迷于文档,现在也厌倦了寻找解决这个问题的方法。也创建了虚拟环境,但仍处于相同位置。您能否建议cloudstorage导入我正在使用的内容以及cloudstorage.open()函数在灵活的环境中是否有效(可以工作)?是否有其他方法从GCS bucket打开csv并根据要求处理文件。这个方法在我看来很简单,但没有得到任何导入问题的解决方案。不,你现在使用的库不起作用。休息一下,然后用正确的文档重新开始。