title: Cannot use jinja2 PackageLoader on Google App Engine
body: <p>I'm trying to use the PackageLoader jinja2 provides but I cannot get it to work.</p>
  
  <p>In my <code>app.yaml</code> I have the required libraries declared:</p>
  
  <pre><code>libraries:
  - name: jinja2
    version: latest
  - name: setuptools
    version: latest
  </code></pre>
  
  <p>The smallest example I could create:</p>
  
  <pre><code>import webapp2, sys
  from jinja2 import Environment, PackageLoader
  sys.path += ['lib/somepackage']
  
  class Test(webapp2.RequestHandler):
      def get(self):
          env = Environment(loader=PackageLoader('common'))
          self.response.write(env.get_template('test.html').render())
  
  routes = [(r"/", Test)]
  app = webapp2.WSGIApplication(routes, debug=True)
  </code></pre>
  
  <p>The package <code>common</code> exists in the directory <code>lib/somepackage</code> and has a package <code>templates</code> which contains a file <code>test.html</code>. The html file only contains the text 'test'.</p>
  
  <p>When the <code>PackageLoader</code> is constructed it's <code>provider</code> is always a <code>NullProvider</code> when in Google App Engine. When I manually request a provider I get a <code>DefaultProvider</code> so obviously something is wrong here.</p>
  
  <p>To request a provider I ensure <code>lib/somepackage</code> is in the <code>sys.path</code> by going to that dir, then:</p>
  
  <pre><code>&gt;&gt;&gt; import pkg_resources
  &gt;&gt;&gt; provider = pkg_resources.get_provider('common')
  &gt;&gt;&gt; provider
  &lt;pkg_resources.DefaultProvider instance at 0x8490b2c&gt;
  </code></pre>
  
  <p>When this fails in Google App Engine, this is the relevant part of the traceback:</p>
  
  <pre><code>  File "/&lt;&gt;/test/main.py", line 7, in get
      self.response.write(env.get_template('test.html').render())
    File "/&lt;&gt;/google_appengine/lib/jinja2-2.6/jinja2/environment.py", line 719, in get_template
      return self._load_template(name, self.make_globals(globals))
    File "/&lt;&gt;/google_appengine/lib/jinja2-2.6/jinja2/environment.py", line 693, in _load_template
      template = self.loader.load(self, name, globals)
    File "/&lt;&gt;/google_appengine/lib/jinja2-2.6/jinja2/loaders.py", line 115, in load
      source, filename, uptodate = self.get_source(environment, name)
    File "/&lt;&gt;/google_appengine/lib/jinja2-2.6/jinja2/loaders.py", line 226, in get_source
      if not self.provider.has_resource(p):
    File "/&lt;&gt;/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 1170, in has_resource
      return self._has(self._fn(self.module_path, resource_name))
    File "/&lt;&gt;/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 1218, in _has
      "Can't perform this operation for unregistered loader type"
  NotImplementedError: Can't perform this operation for unregistered loader type
  </code></pre>
  
  <p>When I use a <code>FileSystemLoader</code> instead it works, however this won't work in a zip I guess:</p>
  
  <pre><code>import common.templates
  env = Environment(loader=FileSystemLoader(common.templates.__path__))
  </code></pre>
  
  <p>I have seen <a href="https://stackoverflow.com/questions/3809304/jinja2-packageloader-on-google-app-engine">this SO question</a> but this isn't the problem.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I just tested the example in the 1.7.6 SDK and this works, however I'd love to see this working on a older SDK (or the old_dev_appserver).</p>