question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Django 1.9 Exception: InvalidTemplateLibrary

See original GitHub issue

Obviously, this is prep-work to make django-extensions compatible with Django 1.9.

Due to the change mentioned here, django-extensions will ‘break’ Django: https://docs.djangoproject.com/en/dev/releases/1.9/#template-tag-modules-are-imported-when-templates-are-configured.

Traceback:

Environment:


Request Method: GET
Request URL: http://localhost:8000/

Django Version: 1.9.dev20150721153804
Python Version: 3.4.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_extensions']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Traceback:

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/utils.py" in __getitem__
  86.             return self._engines[alias]

During handling of the above exception ('django'), another exception occurred:

File "/Users/jaddison/.virtualenvs/django19test/lib/python3.4/site-packages/django_extensions/templatetags/highlighting.py" in <module>
  41.     from pygments import highlight as pyghighlight

During handling of the above exception (No module named 'pygments'), another exception occurred:

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/backends/django.py" in get_package_libraries
  144.             module = import_module(entry[1])

File "/Users/jaddison/.virtualenvs/django19test/lib/python3.4/importlib/__init__.py" in import_module
  109.     return _bootstrap._gcd_import(name[level:], package, level)

File "/Users/jaddison/.virtualenvs/django19test/lib/python3.4/site-packages/django_extensions/templatetags/highlighting.py" in <module>
  45.     raise ImportError("Please install 'pygments' library to use highlighting.")

During handling of the above exception (Please install 'pygments' library to use highlighting.), another exception occurred:

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/jaddison/projects/django19test/testviews/views.py" in testview
  5.     return render(request, template)

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/shortcuts.py" in render
  67.             template_name, context, request=request, using=using)

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/loader.py" in render_to_string
  91.             template = get_template(template_name, using=using)

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/loader.py" in get_template
  21.     engines = _engine_list(using)

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/loader.py" in _engine_list
  139.     return engines.all() if using is None else [engines[using]]

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/utils.py" in all
  110.         return [self[alias] for alias in self]

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/utils.py" in <listcomp>
  110.         return [self[alias] for alias in self]

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/utils.py" in __getitem__
  101.             engine = engine_cls(params)

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/backends/django.py" in __init__
  31.         options['libraries'] = self.get_templatetag_libraries(libraries)

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/backends/django.py" in get_templatetag_libraries
  49.         libraries = get_installed_libraries()

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/backends/django.py" in get_installed_libraries
  131.             for name in get_package_libraries(pkg):

File "/Users/jaddison/.virtualenvs/django19test/src/django/django/template/backends/django.py" in get_package_libraries
  148.                 "trying to load '%s': %s" % (entry[1], e)

Exception Type: InvalidTemplateLibrary at /
Exception Value: Invalid template library specified. ImportError raised when trying to load 'django_extensions.templatetags.highlighting': Please install 'pygments' library to use highlighting.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
adamlwgriffithscommented, Mar 9, 2016

As an aside, if someone else ends up here looking for solutions to InvalidTemplateLibrary errors, check for old .pyc files. Now that Django pre-loads all files in the templatetags module, old .pyc files will be loaded automatically.

0reactions
trbscommented, Jul 27, 2015

Great, thanks for the report !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django 1.9 Exception: InvalidTemplateLibrary #478 - GitHub
I would suggest to move the imports inside the functions where they are used or allow them to fail silently at the module...
Read more >
I'm trying to install django=1.9 on ubuntu using python and I'm ...
I'm trying to install django=1.9 on ubuntu using python and I'm getting the following errors for admin login ; 2017 07:33 ; 2017...
Read more >
Exception Value: Invalid template library specified. ImportError ...
I solved this problems with Django 1.8.7. Django 1.9 is not supported. (oscar) $ make install. (oscar) $ pip install Django== ...
Read more >
Django 1.9 library changes
It's interesting to figure out strange problems that come up due to API changes. Consider this awkward code: import importlib try: from ...
Read more >
invalid template library specified. importerror raised when ...
And run the server I got the error. django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found