9

I've got a local Python application configured with

runtime: python

in it's app.yaml file. When starting the local development server with

dev_appserver.py app.yaml

all is fine.

Since GAE's Local Development Server uses Python2.7 by default, I now want to make use of Python3.x instead. According to Google's documentation, we have to use the flexible environment. Thus I'm changing app.yaml to:

runtime: python
env: flex

runtime_config:
  python_version: 3

Now dev_appserver.py app.yaml spits out:

Under dev_appserver, runtime:python is not supported for Flexible environment.

The problem can be reproduced with Google's Hello World application that uses the flexible environment as well.

So locally we can't use Python3? How can we then run my Python3 code locally before uploading it?

Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127

2 Answers2

9

Using the Local Development Server is applicable to the first generation standard environment apps only.

For running locally flexible env apps see Running locally:

You run your application locally with the native development tools that you usually use.

For example, you can usually run a Flask application with Flask's development server using:

python main.py

Django applications can be started using:

python manage.py runserver

Related: How to tell if a Google App Engine documentation page applies to the standard or the flexible environment

Update:

Support for the 2nd generation standard environment is limited, see Python 3.7 Local Development Server Options for new app engine apps

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • 1
    Do you imply that I can't simulate a local run of my application as if it was running on Google's cloud server? – Lars Blumberg Sep 26 '17 at 17:51
  • 3
    Au contraire. Running your native development tools is the proper way to simulate your flex env app (this is exactly how they will run on GAE - as instructed by the `entrypoint:` config equivalent), `dev_appserver.py` only simulates the GAE standard env python sandbox in which only standard env apps run. – Dan Cornilescu Sep 26 '17 at 18:32
  • @DanCornilescu but how can you similate the extact sandbox if python manage.py runserver runs in local env, were you can install other stuff that are not in the app engine?, but thank you it is a good clarification the local dev env for standard apps only – Manza Aug 18 '18 at 01:19
  • @Manza Well, it's up to you to ensure you only install stuff in the local environment that you also specify as requirements for your app. See https://stackoverflow.com/questions/50627798/adding-a-local-repository-for-dependency-injection-in-python-on-google-cloud/50633000#50633000 – Dan Cornilescu Aug 18 '18 at 12:59
  • @DanCornilescu thats true, however if you have other software install for instance if you use pdfkit and you already have install wkhtmltopdf, this is going to work in your new env, but not in app engine. But yeah ill keep it in mind – Manza Aug 18 '18 at 21:04
1

Adding an updated answer (in 2022)

  1. Google App Engine supports running Python 3 Apps using dev_appserver.py (not for Windows though)

  2. Per their documentation, ....To run dev_appserver with a Python 3 interpreter, you must specify the --runtime_python_path=[PATH_TO_PYTHON3_BINARY] flag....

  3. Some of the bundled services (built-in APIs) like User, Memcache, Datastore, Namespace Manager are also now available for Python3 Apps. When you enable them and use dev_appserver.py to run your Python3 App, you get the same behavior you're used to in Python2 i.e. you will get a simulated datastore, memcache, users, etc

NoCommandLine
  • 5,044
  • 2
  • 4
  • 15