The following line in my Google App Engine app (webapp.py
) fails to import the Google Cloud library:
from google.cloud import storage
With the following error:
ImportError: No module named google.cloud.storage
I did some research and found the following articles to be helpful:
- https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27#installing_a_library
- https://stackoverflow.com/a/34585485
- https://www.simonmweber.com/2013/06/18/python-protobuf-on-app-engine.html
Using a combination of the techniques suggested by the above articles, I did the following:
Create a
requirements.txt
file:google-cloud==0.19.0
Import this library using
pip
:pip install -t lib -r requirements.txt
Use the following code in my
appengine_config.py
file:import os import sys import google libDir = os.path.join(os.path.dirname(__file__), "lib") google.__path__.append(os.path.join(libDir, "google")) sys.path.insert(0, libDir)
Can anyone shed light on what I might be missing to get this working? I'm just trying to write a Google App Engine app that can write/read from Google Cloud Storage, and I'd like to test locally before deploying.