Setup Python 3.7 for Google App Engine Standard

August 30, 2018

Create a google cloud project with app engine.

You shall be promoted to selected a Region (and this CANNOT be changed after selection).

NOTE: A reference for latency across region using GCP.

NOTE: If you intend to use some Beta products, I would recommend us-central.

Create a virtualenv for your project.

virtualenv -p python3 env
source env/bin/activate

NOTE: Though the official documentation use virtualenv env, but you might end up with python2 depending what is your default python version. Check python version python --version.

NOTE: I opt for using pyenv with virtualenv instead.

Make a directory for your project.

mkdir <PROJECT>
cd <PROJECT>

Edit requirements.txt to specify all the dependencies.

Flask==1.0.2

Install the dependencies (for local development).

pip install  -r requirements.txt

Create main.py.

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
  return "Hello"

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8088, debug=True)  

Run the application.

python main.py

NOTE: dev_appserver is no longer the prefered way for local development.

Access the web page at http://127.0.0.1:8088.

Edit app.yaml.

runtime: python37

Deployment.

gcloud app deploy --project <PROJECT> -v 1

You might be interested of the following:

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.