I’m trying to upgrade my app engine app from python 2 to python 3. My app uses the app engine datastore (now cloud datastore). Google’s docs are not at all clear about how to test this stuff locally. I’ve tried dev_appserver.py (which I’ve used for years with Python 2) but that’s yielding the following error:
File "/usr/lib/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 108, in <module>
assert sys.version_info[0] == 2
AssertionError
I do have both Python 3 & Python 2 installed.
… I’m using Ubuntu for development in a Python virtual environment
Thank you
2
Answers
The short answer is that dev_appserver.py does now work with Python 3. Either invoke it directly with python3 or make sure that python3 is the default python interpreter.
File "/usr/lib/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 108, in assert sys.version_info[0] == 2 AssertionError
The above error means you tried to start
dev_appserver.py
with a non-python2 executable.dev_appserver.py
needs to be invoked with Python2 no matter the runtime or version in which your target App is written (i.e. even if your App is written in Python 3). As the documentation saysSummary: Make sure
Python2
is your default Python executable in which case you can simply dodev_appserver.py app.yaml
. IfPython2
isn’t your default Python executable, then you have to use the commandpython2 dev_appserver.py
If you use the bundled APIs, then I don’t believe you’ll need the Cloud Datastore Emulator. You can run your App the same way you were doing it for Python 2. To enable bundled APIs for Python 3, see Google documentation