Python 3.7 Local Development Server Options for new app engine apps

Viewed 3385

I have an app-engine app that is deployed and running on the standard Python3 runtime. I am also able to run it locally using normal commands like flask run. But I am unable to run it the way I could run apps in the 2.7 runtime with dev_appserver.py. I am using the latest gcloud version, but running dev_appserver.py results in:

ERROR: Python 3 and later is not compatible with the Google Cloud SDK. Please use Python version 2.7.x.

I assumed we just aren't supposed to do it this way any more until it saw: https://cloud.google.com/appengine/docs/standard/python3/tools/local-devserver-command

Which starts with:

Python 3.7 Local Development Server Options

Usage:
dev_appserver.py [options] yaml_path [files...]

Is dev_appserver.py compatible with Python3 or not (maybe I somehow have an old version in my path)? If not, is there a new way to run apps locally that will adhere to the app.yaml(like treating static paths correctly) and give other niceties like the local data store that dev_appserver.py provided?

3 Answers

The dev_appserver.py support for Python 3 is still limited. From Running the local development server:

Note:

  • Running dev_appserver requires the presence of Python 2.7.12+ on your local machine.
  • The updated dev_appserver does not support development of Python 3 apps on Windows.

Which might be why it is not the recommended solution for local development (or at least not yet). From Running locally:

We do not recommend that you depend on tools like dev_appserver, the local development server provided with the Google Cloud SDK. However, if you are migrating an existing App Engine application from Python 2 to Python 3, we have updated dev_appserver to facilitate this process. For all other local development scenarios, we recommend standard Python testing approaches.

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

To simulate a production App Engine environment, you can run the full Web Server Gateway Interface (WSGI) server locally. To do this, use the same command specified as entrypoint in your app.yaml, for example:

gunicorn -b :$PORT main:app

For windows 10 :

The solution was to install a linux subsystem for windows : https://docs.microsoft.com/en-us/windows/wsl/install-win10

I use the Ubuntu app from the windows store, and follow the installation for installing the gcloud component on linux inside the ubuntu terminal: https://https://docs.microsoft.com/en-us/windows/wsl/install-win10cloud.google.com/sdk/docs/#deb

Inside the Ubuntu terminal it is possible to access the windows file : the C drive would be /mnt/c. Getting back to my work folder, it is possible to start the web-app using the dev_appserver command.

Using a navigator from windows we have access to the web-app as normal using localhost:8080.

The development can still be done using an IDE in windows, running the server in Ubuntu.

Adding an update in 2022

  1. From the link Running the local development server mentioned by @dan-cornilescu in his response, they have changed the verbiage and removed the text that says ...we do not recommend that you depend on tools like dev_appserver.... . Instead the text now says

We recommend that you use standard Python tools, such as virtualenv to create isolated environments...

  1. It also looks like they have enhanced dev_appserver.py to work with Python 3. Running the local development server now says

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

  1. I don't know why their documentation gives the impression that the advantage of using standard python tools over dev_appserver.py is to be able to have virtual env given the fact that when you run your Python3 App with dev_appserver.py, it will first create a temp folder, create a virtual environment in that folder and install the contents of your requirements.txt file there.

  2. The downside with using dev_appserver.py is that each time you start your App, it will create a new virtual env and reinstall the contents of your requirements.txt. This means that while you're still troubleshooting your App (which might involve multiple restarts), you will end up with lots of folders in your tmp directory and these are not deleted when the app is shut down. There is also the time it takes to install the requirements.

  3. If you start the Cloud Datastore Emulator and set the flag for dev_appserver.py to use it, then you'll be able to view your data in the same UI that you're used to for Python 3 projects (@michael this should answer your question about UIs). Below is a screen shot

    enter image description here

  4. There are also 3rd party UIs from - https://github.com/GabiAxel/google-cloud-gui, https://www.npmjs.com/package/google-cloud-gui

  5. Our App, NoCommandLine also has a UI for datastore

    enter image description here

Related