Domanda

I'm going through the GAE webapp2 tutorial (runtime 2.7) using GoogleAppEngineLauncher on my Mac, and though I'm following everything exactly, I keep on getting an error at the point where we import the Jinja2 module: Using Templates - Google App Engine

Error:

Traceback (most recent call last): File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 168, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 206, in _LoadHandler handler = import(path[0]) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 640, in Decorate return func(self, *args, **kwargs) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1756, in load_module return self.FindAndLoadModule(submodule, fullname, search_path) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 640, in Decorate return func(self, *args, **kwargs) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1628, in FindAndLoadModule description) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 640, in Decorate return func(self, *args, **kwargs) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1571, in LoadModuleRestricted description) File "/Users/ykessler/Dropbox/appgrinders/gae_apps/helloworld2.7/helloworld.py", line 9, in import jinja2 ImportError: No module named jinja2

So it for some reason can't find the module, even though it's supposed to be packaged as part of webapp2's extras. When I do a search on my file system it looks like it's there:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2_extras/jinja2.py

And if I deploy the app to GAE, it works fine. Why would it be failing locally?

È stato utile?

Soluzione

webapp2 packages its own jinja2 'glue' module, which is what you're importing, but it doesn't package jinja2 itself. If you want to use it, you'll need to install it in your system Python using easy_install, or put it in your app's directory.

Altri suggerimenti

Don't use the latest parameter on the app.yaml file, specify a version to prevent a highly unlikely but nonetheless possible incompatibility catastrophe.

Alias, specify 2.6, which is the only one supported, acording to the docs.

libraries:
- name: jinja2
  version: "2.6"

Then, at your script, just import jinja2, as we're told by the docs.

I got this error too, to fix it I needed to add jinja2 to the bottom of my app.yaml file (as it says at the start of the tutorial .. )

First add the following to the bottom of helloworld/app.yaml:

libraries:
- name: jinja2
  version: latest
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top