Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine jinja2: ImportError: No module named _markupsafe

If you follow the Python2.7 getting started guide, you get to the templating part here. For me on Ubuntu 11.10 I would get a horrible stack trace that ended with:

  File "/home/fratrik/code/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1571, in LoadModuleRestricted
    description)
  File "/usr/lib/python2.7/dist-packages/jinja2/utils.py", line 587, in <module>
    from jinja2._markupsafe import Markup, escape, soft_unicode
ImportError: No module named _markupsafe

The important part is actually at the top:

ERROR    2011-11-13 00:48:12,767 dev_appserver_import_hook.py:1386] Third party package markupsafe must be included in the "libraries:" clause of your app.yaml file in order to be imported.
like image 942
fratrik Avatar asked Nov 13 '11 00:11

fratrik


2 Answers

The answer is to add the following to your app.yaml

libraries:                                                                      
- name: jinja2                                                                  
  version: latest                                                               
- name: markupsafe                                                              
  version: latest                                                                                

(for python2.7)

like image 159
fratrik Avatar answered Oct 19 '22 15:10

fratrik


You can import the jinja2 module that is coming with the app engine sdk. Add the path of google_appengine/lib/webapp2 and google_appengine/lib/webapp2/webapp2_extras directories to your $PYTHONPATH.

import webapp2
from webapp2_extras import jinja2

along with the yaml entries.

like image 25
topless Avatar answered Oct 19 '22 15:10

topless