Bug 882016

Summary: Installing python-jinja2 neither installs in python path nor sets python path
Product: [Fedora] Fedora EPEL Reporter: Will Thames <will>
Component: python-jinja2-26Assignee: Thomas Moschny <thomas.moschny>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: el6CC: pingou, thomas.moschny
Target Milestone: ---   
Target Release: ---   
Hardware: noarch   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-12-09 10:40:20 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.