ImportError: cannot import name 'pubsub_v1' from 'google.cloud' (unknown location)

白昼怎懂夜的黑 提交于 2019-12-24 06:11:15

问题


I am trying to import the pubsub_v1 in a cloud function. But when I tried to deploy it on GCP, the problem as in the title coming out. The requirements.txt file is in the same directory as the main.py file. Here is what in the requirements.txt:

google-api-core==1.3.0
google-auth==1.5.1
google-cloud-core==0.28.1
google-cloud-storage==1.10.0
google-resumable-media==0.3.1
googleapis-common-protos==1.5.3
google-api-python-client==1.7.4
oauth2client==4.1.2
google-cloud-bigquery==1.5.0
google-cloud-logging==1.7.0
google-cloud-pubsub==0.26.0
proto-google-cloud-pubsub-v1==0.15.4
gapic-google-cloud-pubsub-v1==0.15.4
grpc-google-iam-v1==0.11.4

I used the following command to deploy the cloud function:

gcloud functions deploy some_function --runtime python37 --trigger-resource bucket --trigger-event google.storage.object.finalize --memory 2048 --timeout 500

回答1:


You're using a pretty old version of google-cloud-pubsub. You'll only be able to do:

from google.cloud import pubsub_v1

with google-cloud-pubsub>=0.28.1.

Also, it might worth mentioning that you probably don't need to list all the sub-dependencies (like gapic-google-cloud-pubsub-v1) in your requirements.txt -- when you deploy your function, Google Cloud Functions will resolve all these for you just by specifying google-cloud-pubsub.



来源:https://stackoverflow.com/questions/52636483/importerror-cannot-import-name-pubsub-v1-from-google-cloud-unknown-locatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!