RogB
RogB

Reputation: 461

No module named 'google.appengine' from within Cloud Shell

I'm testing Google App Engine and trying to run a simple function to upload files to either the Blobstore or Cloud Storage. I'm typing the Python code directly in the Cloud Shell of my instance. The code is failing when I call:

from google.appengine.ext import blobstore

I get the error code:

Traceback (most recent call last): File "upload_test.py", line 1, in <module> from google.appengine.api import users ImportError: No module named 'google.appengine'

Even though the documentation says that: You can use Google Cloud Shell, which comes with git and Cloud SDK already installed, I've tried installing a bunch of libraries:

gcloud components install app-engine-python

pip install google-cloud-datastore

pip install google-cloud-storage

pip install --upgrade google-api-python-client

I'm still getting the same error. How can I get the appengine library to work? Alternatively, is this the wrong method for creating an app that allows the user to upload files?

Upvotes: 2

Views: 1516

Answers (2)

RogB
RogB

Reputation: 461

Thanks @Dustin Ingram

I found the answer in this page.

The current "correct" way of uploading to Cloud Storage is to use google.cloud.storage. The tutorial I linked above explains how to implement it.

The impression I have, however, is that this uses twice the bandwidth as the solution via google.appengine. Originally, the front-end would receive an upload url and send the file directly to the Blobstore (or to Cloud Storage). Now the application uploads to the back-end which, in turn, uploads to Cloud Storage.

I'm not too worried, as I will not be dealing with excessively large files, but it seems strange that the ability to upload directly has been discontinued.

In any case, my problem has been solved.

Upvotes: 0

Dustin Ingram
Dustin Ingram

Reputation: 21580

The google.appengine module is baked into the first-generation Python (2.7) runtime. It's not available to install via pip, in the second-generation (3.7) runtime, or in Cloud Shell.

The only way to use it is by writing and deploying a first-generation App Engine app.

Upvotes: 5

Related Questions