2011-11-14 96 views
8

我正在使用我的Mac上的GoogleAppEngineLauncher通過GAE webapp2教程(運行時2.7),儘管我完全遵循所有內容,但我仍然在地步,我們導入的Jinja2模塊:Using Templates - Google App Engine無法使用webapp2/Google App Engine加載jinja2

錯誤:

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

因此,出於某種原因無法找到該模塊,即使它應該被打包成webapp2的的額外的一部分。當我將文件系統上做一個搜索,它看起來像它的存在:

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

如果我部署應用GAE,它工作正常。爲什麼它會在本地失敗?

+0

你爲什麼編輯你的問題來刪除有用的細節? –

+0

重新添加stacktrace – Yarin

回答

7

webapp2打包自己的jinja2'glue'模塊,這就是你正在導入的模塊,但它並不打包jinja2本身。如果您想使用它,您需要使用easy_install將其安裝在系統Python中,或者將其放入應用程序的目錄中。

+1

謝謝 - 當我將模塊添加到它工作的應用程序目錄中。那麼'膠水'模塊的目的是什麼? – Yarin

+1

@Yarin檢查webapp2文檔 - 它提供了有用的東西,使它更容易從webapp2使用jinja2。 –

+0

安裝jinja 2最簡單的步驟可以在這裏找到(http://jinja.pocoo.org/docs/intro/#from-the-tarball-release) – Boinst

2

我得到這個錯誤太,解決它,我需要的Jinja2添加到我的app.yaml文件的底部(因爲它說,在教程開始..)

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

libraries: 
- name: jinja2 
    version: latest 
7

不要在app.yaml文件中使用latest參數,指定一個版本以防止出現極不可能但卻可能出現的不兼容性災難。

別名,根據the docs指定2.6,這是唯一支持的。

libraries: 
- name: jinja2 
    version: "2.6" 

然後,在你的腳本,只是import jinja2,因爲我們被告知the docs

相關問題