Can't run sample applications on AppEngine Stanadard Python3.7

495 views
Skip to first unread message

vvv vvv

unread,
Sep 27, 2018, 8:28:34 PM9/27/18
to Google App Engine

Hello, after installing everything, I am trying to run ~/python-docs-samples/appengine/standard_python37/building-an-app/building-an-app-2
building-an-app/building-an-app-1 built and run successfully, my problem is with the rest in the series which use the cloud datastore.
When i start my virtual environment and run
pip3 install -r requirements.txt

python3 main
.py


I get Traceback (most recent call last):
  File "main.py", line 20, in <module>
   
from google.cloud import datastore
 
File "/home/neptune/env/local/lib/python3.6/site-packages/google/cloud/datastore/__init__.py", line 61, in <module>
   
from google.cloud.datastore.batch import Batch
 
File "/home/neptune/env/local/lib/python3.6/site-packages/google/cloud/datastore/batch.py", line 24, in <module>
   
from google.cloud.datastore import helpers
 
File "/home/neptune/env/local/lib/python3.6/site-packages/google/cloud/datastore/helpers.py", line 24, in <module>
   
from google.type import latlng_pb2
ModuleNotFoundError: No module named 'google.type'


If on the other hand I run:

pip install -r requirements.txt

python main
.py


The output is:
  File "main.py", line 22, in <module>
    datastore_client
= datastore.Client()
...
    psep
= app_id.find(_PARTITION_SEPARATOR)
AttributeError: 'NoneType' object has no attribute 'find'


I found here (https://github.com/GoogleCloudPlatform/google-cloud-datastore/issues/168) in the end that I have to set APPLICATION_ID. How do I do this, and is this documented somewhere?

George (Cloud Platform Support)

unread,
Sep 27, 2018, 9:20:12 PM9/27/18
to Google App Engine
The recommended way to run Standard Environment applications in the local environment is by using the dev_appserver.py command as follows, from the directory that contains your app's app.yaml configuration file, and specifying the directory path to your app, for example:

dev_appserver.py [PATH_TO_YOUR_APP]

You may find related detail on the "Using the Local Development Server" documentation page

Stewart Reichling

unread,
Sep 28, 2018, 12:25:32 PM9/28/18
to Google App Engine
Quick correction to George's post:
  • for Python 2.7, dev_appserver is recommended
  • for Python 3.7, we recommend using Python's idiomatic development practices, as listed on this page
But back to the original question -- are you following the instructions on this section of the doc?

vvv vvv

unread,
Sep 28, 2018, 1:50:57 PM9/28/18
to Google App Engine
Hi George, thanks for answering. dev_appserver.py is for the standard environment Python 2.7, I'm trying to run a Python 3.7 web app.

Rahul Ravindran

unread,
Sep 28, 2018, 2:04:22 PM9/28/18
to Google App Engine

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/5d3c5a27-d2d1-4619-9b47-4df1378828a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vvv vvv

unread,
Sep 28, 2018, 3:45:27 PM9/28/18
to Google App Engine
OK here's an update of how I fixed this issue, with a question at the end. It's true that you have to run:
export APPLICATION_ID=myapplicationnamegoeshere
before you can run "python main.py" to run the example that connects to the (local) Cloud Datastore. Before you run this command you have to run these commands to bring up a local Datastore:
sudo apt-get install google-cloud-sdk-datastore-emulator
gcloud beta emulators datastore start
$
(gcloud beta emulators datastore env-init)

Then if you follow the instructions you can find in the docs the application will run OK. I think the docs have to be updated to include these info. My question is the following:
How is it possible that when I run the python 3 version of all these commands (3.16 on my Ubuntu), and even using "virtualenv -p python3 envname", I get the "ModuleNotFoundError: No module named 'google.type'" error, but with the Python 2.17 version of the commands the application runs OK. Is this supposed to be like this? I thought the environment the app runs on was supposed to be 3.17? 

El viernes, 28 de septiembre de 2018, 1:28:34 (UTC+1), vvv vvv escribió:

vvv vvv

unread,
Sep 28, 2018, 8:28:25 PM9/28/18
to Google App Engine
OK all problems fixed!

The origin of the problems was that I had installed Python App Engine 2.7 before all of this, and trying to migrate  to App Engine 3.7.
The problem was that "/usr/lib/google-cloud-sdk/platform/google_appengine" was in my PYTHONPATH. Probably because this directory contains a "google" subdirectory, but no "type" subdirectory inside "google". I'm not sure if this was the problem... What I did that fixed this was i ran "sudo apt remove google-cloud-sdk" and then installed again the latest SDK with "sudo apt-get update && sudo apt-get install google-cloud-sdk", which didn't create this folder again. It created "/usr/lib/google-cloud-sdk/platform/" but with no "google_appengine" inside it. Also I should have a look at how to remove that dir from my PYTHONPATH as it doesn't exist any more.

After all this I just had to create an authentication and setting "export GOOGLE_APPLICATION_CREDENTIALS="pah to file.json", and then "python main.py" started the application using python 3.6 interpreter.
Thanks!

El viernes, 28 de septiembre de 2018, 1:28:34 (UTC+1), vvv vvv escribió:
Reply all
Reply to author
Forward
0 new messages