import webapp2 works on google-app-engine even tho

2019-01-24 23:26发布

问题:

When I run the following hellow world program (with the GAE Launcher) it works:

import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!')

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

However If i go to the terminal I can't import webapp2:

C:\Users\Robert>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import webapp2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named webapp2
>>>

Also my IDE provides no autocomplete for webapp2 objects.

Seeing as GAE Launcher uses the same python version as I use in the terminal, I'm confused as to how the import must work within the GAE launcher.

回答1:

It's not a bug. Appengine SDK includes webapp2 since version 1.6.

By default, you can not import webapp2 from the terminal because google_appengine is not added to PATH by default.

Add the following dirs to Python's PATH; C:\Program Files\Google\google_appengine\ and C:\Program Files\Google\google_appengine\lib\ and you will have the same enviroment the SDK provides.



回答2:

i dont use the GAE launcher but im pretty sure that if you start your app with the launcher it puts some packages into your pythonpath thats why you can import it in your app.
i bet you cant import something from the gooogle.appengine.ext or other gae libs from your python prompt but you can in your app.



回答3:

Are you using the python27 runtime? If so, webapp2 is available on both the development server, regardless of whether you have it installed, and the production runtime. If you're able to import webapp2 under the old python 2.5 runtime, I would consider this a bug.