11
votes

I'm trying to deploy an example dart server using Google AppEngine. However when I run this python script (with the latest python version installed 3.5)

dev_appserver.py

I've also tried

dev_appserver.py --custom_entrypoint "dart bin/server.dart {port}" app.yaml

I get this error:

Traceback (most recent call last):
  File "C:\Users\jkrie\AppData\Local\Google\Cloud SDK\google-cloud- sdk\bin\dev_appserver.py", line 11, in <module>
    import bootstrapping.bootstrapping as bootstrapping
  File "C:\Users\jkrie\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\bootstrapping\bootstrapping.py", line 9, in <module>
    import setup

ImportError: No module named 'setup'

I've also installed setuptools. I have to assume there is something wrong with my Google Cloud SDK install, but I really don't know what. Is python 3.5 too new and I need to try an older version?

7

7 Answers

4
votes

Indeed you have to use Python 2 for the standard App Engine environment for the time being.

If you have Python 3 installed, you can create a virtualenv using Python 2 using mkvirtualenv google --python=$(which python2) and run dev_appserver.py . in that environment.

This saves you the hassle of having to downgrade or symlink python to python2

4
votes

Google could prepend the file with

#!/usr/bin/env python2

instead of

#!/usr/bin/env python

It would make their tools compatible with OSs that use python3 as default.

2
votes

As @dan-cornilescu said GAE Standard Environment support only Python2.7

If you are in an environment with multiversion of Python, you could easly use Pipenv to run your dev_appserver.py with Python 2.7 version.

After you have installed pipenv globaly you could create a pipenv environment inside your project folder with Python 2.7

# pipenv install --twoo

Every time you need to run dev_appserver.py you should use this command

# pipenv run dev_appserver.py app.yaml

pipenv will use Python 2.7 to run your code. ;-)

0
votes

I had this issue since I install both python2.9 and python3.6. Quick way without uninstall python3 is just delete python3 path in environment variables while you are using GAE. Add them back when done with GAE.

0
votes

I had the same problem with a very simple python35 app (now, a year later!) I did create a python27 virtual environment which does work, but needed more workarounds.

The easiest thing is to just run python applicationmodule.py on the shell command line, ensuring you have this at the bottom:
if __name__ == '__main__': # This is used when running locally. Gunicorn is used to run the # application on Google App Engine. See entrypoint in app.yaml. app.run(host='127.0.0.1', port=8080, debug=True)

If you want to run using dev_appserver.py then, I found I needed to run the following to make this work on the Google Cloud Shell:dev_appserver.py app.yaml --custom_entrypoint ./applicationmodule.py

In that case, make sure the applicationmodule.py doesn't have the if __name__ == '__main__': code. If you do have this, then it starts the same task again and complains about contention on port 8080.

This is different from other answers which have the --custom_entrypoint parameter looking more like the app.yaml entrypoint: entry.

At one point executing dev_appserver.py complained about executing applicationmodule.py (I forget exactly), so I did both chmod 777 and I added a #! pointing to my local python executable - it worked after having done both, but don't know if it was the chmod or the #! that did it.

0
votes

App Engine now supports Python 3 from version 3.7.

Here's a quick start guide and some differences between the support for versions 2.7 and 3.7.