google-app-enginegoogle-cloud-platformgoogle-app-engine-pythongoogle-cloud-sdkdev-appserver

Google App Engine: No module named setup


I am new to GAE and while doing a course, I needed to install it on my system. I followed the instructions on the GAE website, and it successfully installed on my Ubuntu 17.04 system. Now, I created a folder with the name first-app with the files first-app.py and app.yaml.

Whenever I try to run dev_appserver.py first-app, I get the following error:

Traceback (most recent call last):
  File "/usr/bin/dev_appserver.py", line 11, in <module>
    import bootstrapping.bootstrapping as bootstrapping
  File "/usr/lib/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 9, in <module>
    import setup
ModuleNotFoundError: No module named 'setup'

I have both python 2.7 and python 3.5 installed and the default python is 2.7.13.

Below is the content of first-app.py:

import webapp2

class Mainpage(webapp2.RequestHandler):
    def get(self):
        self.response.write("Hello World")

app=webapp2.WSGIApplication([('/', Mainpage), ], debug=True)

and the content of app.yaml file is:

runtime: python
api_version: 1
threadsafe: true

handlers:
- url: /
  script: first-app.app

- url: /index\.html
  script: home.app

What should I do to make it work?


Solution

  • It appears that you're somehow ending up running it with python 3, see:

    In addition to trying the answers to those questions I'm thinking you could also try explicitly selecting the python version, like this:

    python2.7 /usr/bin/dev_appserver.py [first-app ...]
    

    A more "permanent" alternative which wouldn't require you to do the above for every invocation would be to modify (as root) /usr/bin/dev_appserver.py and replace #!/usr/bin/env python at the top with #!/usr/bin/env python2.7. With this change it should just work normally as long as you have a valid 2.7 python installation on your system, even if it's not the default one.

    It may appear hacky, but given that dev_appserver.py can only be used with standard env GAE apps, which only supports python 2.7, IMHO it's rather natural - Google could have done it in this particular case. But since they didn't, just re-member to re-do it when needed as SDK updates will probably wipe it away.