Sunday, 11 August 2019

Can no longer create a packageloader in jinja2

When I try to create a packageLoader in Jinja2 with:

loader=jinja2.PackageLoader( 'cyan', 'templates')

I get an error:

In [2]: loader=PackageLoader( 'cyan', 'templates')                                                      
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/work/venvs/CYAN/lib/python3.7/site-packages/pkg_resources/__init__.py in get_provider(moduleOrReq)
    358     try:
--> 359         module = sys.modules[moduleOrReq]
    360     except KeyError:

KeyError: 'cyan'

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-9f5a5a8d0f55> in <module>
----> 1 loader=PackageLoader( 'cyan', 'templates')

~/work/venvs/CYAN/lib/python3.7/site-packages/jinja2/loaders.py in __init__(self, package_name, package_path, encoding)
    222         from pkg_resources import DefaultProvider, ResourceManager, \
    223                                   get_provider
--> 224         provider = get_provider(package_name)
    225         self.encoding = encoding
    226         self.manager = ResourceManager()

~/work/venvs/CYAN/lib/python3.7/site-packages/pkg_resources/__init__.py in get_provider(moduleOrReq)
    359         module = sys.modules[moduleOrReq]
    360     except KeyError:
--> 361         __import__(moduleOrReq)
    362         module = sys.modules[moduleOrReq]
    363     loader = getattr(module, '__loader__', None)

ModuleNotFoundError: No module named 'cyan'

This USED to work. I haven't figured out what recent change could have caused this. There is a templates directory, it has init.py.

This: HTML templating using Jinja2 No module named your app looks like the same issue, but the suggestion is to not use PackageLoader. Since my code WORKED 2 weeks ago, I'm concerned that I broke something else, and this is just a symptom, so I'd rather not just make the symptom go away, if I can figure out what is actually happening.

The extra weird thing about this is that 'cyan' is the name of the program. In the documentation, it uses "yourapplication" so I assumed it could be any string, and was using it to name things internally...



from Can no longer create a packageloader in jinja2

No comments:

Post a Comment