Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named jinja2, yet it's installed

Tags:

python

jinja2

When I run sudo pip install jinja2 I see: Requirement already satisfied: Jinja2 in /Users/rose/Library/Python/2.7/lib/python/site-packages/Jinja2-2.7.2-py2.7.egg.

Yet running import jinja2 in a new python 2.7 shell gives: ImportError: No module named jinja2

like image 867
Rose Perrone Avatar asked Apr 18 '14 02:04

Rose Perrone


2 Answers

Note that Jinja2 is installed in your home directory, and that Python's site-packages directory is located a /Library/Python/2.7/site-packages. It's likely that either /Users/rose/Library/Python/2.7/lib/python/site-packages/ is not contained in your Python path, or Python does not have access to this directory. This may be the result of installing Jinja2 with pip install jinja2 instead of sudo pip install jinja2.

You can check if /Users/rose/Library/Python/2.7/lib/python/site-packages/ by opening your Python shell:

>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/dist-packages']

If not, the easiest solution may simply be to reinstall Jinja2 as admin:

pip uninstall jinja2
sudo pip install jinja2
like image 87
Mark Egge Avatar answered Sep 20 '22 23:09

Mark Egge


Easiest solution by Mark Edge didn't worked for me, as pip installed jinja2 to place-not-in-path anyway.

Here is my development of solution:

  1. If you don't know or forgot where pip install jinja2, use pip install jinja2 again. You are going to get something like Requirement already satisfied: jinja2 in /usr/local/lib/python2.7/site-packages , and that's the path you need.
  2. There should be .bash_profile file in your home directory ( /Users/Your_username).

I added to it:

export PATH="/usr/local/lib/python2.7/site-packages:$PATH"
PYTHONPATH="$HOME/Scripts/:$PATH"

If you already have PYTHONPATH line like above, add just the export one.

Restart your shell/Terminal windows for them to pick the new path.

Doing that fixed my problem "No module named jinja2"

like image 44
RPWheeler Avatar answered Sep 21 '22 23:09

RPWheeler