2

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
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Han M
  • 389
  • 4
  • 14

1 Answers1

3

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.

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
  • Hi Dustin, thanks! I tried google-cloud-pubsub==0.28.0, but got another error ModuleNotFoundError: No module named 'google.api.core' – Han M Oct 04 '18 at 15:37
  • Looks like there was a bugfix in 0.28.1 that solves that. Is there a reason why you need to pin to these old versions though? The latest is `google-cloud-pubsub==0.38.0` – Dustin Ingram Oct 04 '18 at 19:19