Catch ImproperlyConfigured exception in compat.py (fixes #803)