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

点点圈 提交于 2020-05-30 02:35:14

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/54132755/no-module-named-google-appengine-from-within-cloud-shell

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