Cyril
Cyril

Reputation: 790

ImportError: No module named jinja2

Using google-app-engine tutorial, I got the following error stack message:

Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 298, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 84, in LoadObject
obj = __import__(path[0])
File "D:\Dev\SandBoxes\web\omaha\omaha.py", line 4, in <module>
import jinja2
ImportError: No module named jinja2

Even though I declared it in the libraries from app.yaml:

application: ***
version: 1
runtime: python27
api_version: 1
threadsafe: true

libraries:
- name: jinja2
  version: latest
- name: webapp2
  version: latest


handlers:
- url: /css
  static_dir: css
- url: /js
  static_dir: js
- url: /img
  static_dir: img
- url: /.*
  script: omaha.application

Has anyone had a similar problem?

Upvotes: 37

Views: 156419

Answers (8)

Alan
Alan

Reputation: 19

Please lower the version for jinja.This worked for me.

pip install Jinja2==3.0.3

Upvotes: 1

Ivan Yulin
Ivan Yulin

Reputation: 1046

brew install jinja2-cli

for them brew users

Upvotes: 4

questionto42
questionto42

Reputation: 9532

I had this error when the flask package threw this error:

import flask
  File "/usr/local/lib/python2.7/dist-packages/flask/__init__.py", line 19, in <module>
    from jinja2 import Markup, escape
ImportError: No module named jinja2

Solution:

sudo apt-get install python-flask

It seems to install Jinja as a dependency. Perhaps this helps someone.

Upvotes: 0

user3546879
user3546879

Reputation: 442

Use these commands to get pip and Jija2 installed for Python 3:

sudo apt-get install python3-pip
sudo pip3 install Jinja2

Upvotes: 6

Kees Briggs
Kees Briggs

Reputation: 381

You may not have added the following lines to app.yaml:

- name: jinja2
  version: latest

Upvotes: 5

topless
topless

Reputation: 8221

In order to use Jinja locally, you need to install it locally

easy_install Jinja2

or

pip install Jinja2

Upvotes: 39

Cyril
Cyril

Reputation: 790

Need to restart application in AEL.

The application in Google App Engine Launcher must be restarted for new library calls to be taken into account. I was mislead by the fact all other changes dont need actual restart of the server.

Upvotes: 7

Jesse
Jesse

Reputation: 8393

Even though it's declared in your libraries it doesn't necessarily mean the dev app server can find the library within the appengine sdk.

Since you're running the tutorial, I'm assuming you are running the application from googles app engine launcher. Within the laucher go into "Edit" >> "Prefences" and set your Python Path and SDK Path.

enter image description here

Upvotes: 0

Related Questions