Bug 882016 - Installing python-jinja2 neither installs in python path nor sets python path
Summary: Installing python-jinja2 neither installs in python path nor sets python path
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora EPEL
Classification: Fedora
Component: python-jinja2-26
Version: el6
Hardware: noarch
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Thomas Moschny
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-11-29 23:33 UTC by Will Thames
Modified: 2014-09-29 16:19 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-12-09 10:40:20 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Will Thames 2012-11-29 23:33:56 UTC
Description of problem:
After installing python-jinja2, python cannot find jinja2


Version-Release number of selected component (if applicable):
2.6.2.el6

How reproducible:
Install python-jinja2 and try to use jinja2

Steps to Reproduce:
1. yum install python-jinja2
2. python -c 'import jinja2'
  
Actual results:
ImportError: No module named jinja2

Expected results:
Exits successfully

Additional info:
The difference between the fc17 RPM and the el6 RPM is that fc17 installs jinja2 into /usr/lib/python2.7/site-packages/jinja2, whereas el6 installs it into /usr/lib/python2.6/site-packages/Jinja2-2.6-py2.6.egg/jinja2 - the extra Jinja2-2.6-py2.6.egg is what stops python finding it. 

The fix would be to install jinja2 into the site-packages directory directly, or add a jinja2.pth file that adds the Jinja2-2.6-py2.6.egg to the sys.path (the former is the fc17 approach)

Comment 1 Thomas Moschny 2012-12-09 10:40:20 UTC
Actually, there are two different packages: python-jinja2 is from RHEL6, (rather old) version 2.2.1, and python-jinja2-26 is from EPEL6, (newer) version 2.6.

Obviously, the EPEL package cannot install into site-packages/jinja2, but only installs into site-packages/Jinja2-2.6-py2.6.egg.

In order to import the module, you have to modify sys.path as such:

>>> import sys
>>> sys.path.insert(0, '/usr/lib/python2.6/site-packages/Jinja2-2.6-py2.6.egg')
>>> import jinja2

For more details, see
https://fedoraproject.org/wiki/Packaging:Python_Eggs#Multiple_Versions

This is also explained in /usr/share/doc/python-jinja2-26-2.6/README.Fedora.

Comment 2 Pierre-YvesChibon 2014-09-29 16:19:37 UTC
A better, more sustainable/flexible solution is to use the following two lines at the top of every application:

```
## These two lines are needed to run on EL6
__requires__ = ['SQLAlchemy >= 0.7', 'jinja2 >= 2.4']
import pkg_resources
```

The SQLAlchemy part is of course optional and depends on your application.


Note You need to log in before you can comment on or make changes to this bug.