2

I'm working on a Python project using Google Cloud's pubsub.

In my Python file, there's the following import statement:

from google.cloud import pubsub_v1

Locally everything works as desired, but when I deploy it with:

gcloud app deploy

This error occurs on my app engine:

ModuleNotFoundError: No module named 'google' at (/srv/pubsub/pub.py:21)

What am I doing wrong?

David Buck
  • 3,752
  • 35
  • 31
  • 35
Oguzhan
  • 55
  • 8
  • Does this answer your question? [ImportError: cannot import name pubsub\_v1](https://stackoverflow.com/questions/47011713/importerror-cannot-import-name-pubsub-v1) – stud3nt Jan 12 '20 at 10:39
  • Did you declared the module on your requirements.txt file? Is so please share it with us – Chris32 Jan 12 '20 at 11:45
  • In my requirements.txt I only have declared Flask. Is it required to declare google modules there to make it work? I thought installing it in your env and deploying would be enough. @Chris32 – Oguzhan Jan 12 '20 at 11:54
  • 1
    Yes, just declare google-cloud-pubsub==1.1.0 and try again – Chris32 Jan 12 '20 at 13:07
  • Thank you @Chris32 – Oguzhan Jan 13 '20 at 15:29

1 Answers1

1

Check the requirements.txt. Generally developer test on local but forget to include the library in requirements.txt App Engine will build the code in Cloud Build and will install dependencies listed in the requirements.txt metadata

Vikram Shinde
  • 1,022
  • 6
  • 17