2011-11-14 42 views
8

Tôi sẽ thực hiện hướng dẫn GAE webapp2 (thời gian chạy 2.7) bằng GoogleAppEngineLauncher trên máy Mac của mình và mặc dù tôi đang theo dõi mọi thứ chính xác, tôi tiếp tục gặp lỗi điểm mà chúng tôi nhập khẩu các mô-đun Jinja2: Using Templates - Google App EngineKhông thể tải jinja2 bằng webapp2/Google App Engine

Lỗi:

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

vì vậy, nó vì một lý do không thể tìm thấy các mô-đun, mặc dù nó là nghĩa vụ phải được đóng gói như là một phần của tính năng bổ sung webapp2 của. Khi tôi thực hiện tìm kiếm trên hệ thống tệp của tôi, có vẻ như ở đó:

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

Và nếu tôi triển khai ứng dụng lên GAE, nó hoạt động tốt. Tại sao nó sẽ thất bại tại địa phương?

+0

Tại sao bạn chỉnh sửa câu hỏi của mình để xóa các chi tiết hữu ích? –

+0

Đã thêm lại stacktrace – Yarin

Trả lời

7

gói webapp2 mô-đun jinja2 'keo' của riêng nó, đó là những gì bạn đang nhập, nhưng nó không tự gói jinja2. Nếu bạn muốn sử dụng nó, bạn sẽ cần phải cài đặt nó trong Python hệ thống của bạn bằng cách sử dụng easy_install, hoặc đặt nó vào thư mục của ứng dụng của bạn.

+1

cảm ơn- khi tôi thêm mô-đun vào thư mục ứng dụng đã hoạt động. Vậy mục đích của mô-đun 'keo' là gì? – Yarin

+1

@Yarin Kiểm tra tài liệu webapp2 - nó cung cấp các công cụ hữu ích để giúp sử dụng jinja2 dễ dàng hơn từ webapp2. –

+0

Các bước đơn giản nhất để cài đặt jinja 2 có thể được tìm thấy [ở đây] (http://jinja.pocoo.org/docs/intro/#from-the-tarball-release) – Boinst

2

Tôi đã nhận lỗi này quá, để sửa chữa nó tôi cần phải thêm jinja2 để dưới cùng của tập tin app.yaml của tôi (vì nó nói lúc bắt đầu của hướng dẫn ..)

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

libraries: 
- name: jinja2 
    version: latest 
7

Không sử dụng tham số latest trên tệp app.yaml, chỉ định phiên bản để ngăn chặn thảm họa không tương thích cao nhưng có thể xảy ra.

Bí danh, chỉ định 2.6, là tên duy nhất được hỗ trợ, theo the docs.

libraries: 
- name: jinja2 
    version: "2.6" 

Sau đó, tại tập lệnh của bạn, chỉ import jinja2, như chúng tôi đã nói bởi the docs.

Các vấn đề liên quan