astropy/astropy — pull request #2671 by embray (2014-08-05 20:09:03+00:00)
Title: ImportErrors possible within AstropyLogger

This is kind of obscure and might not be worth fixing

Some people using the Glue mac app (bundled with py2app, see mac.glueviz.org) were running into astropy errors when trying to read files that generate warning messages. I tracked it down to an ImportError being thrown at this line:

https://github.com/astropy/astropy/blob/master/astropy/logger.py#L203

Several email submodules install LazyImporters in sys.modules, that defer actual importing until the first time they are accessed (which happens inside this logger function).

```python
In [11]: import sys, email
In [12]: sys.modules['email.MIMEBase']
Out[12]:
```

Because of this (and because the email module isn't well-supported on py2app), the LazyImporter raises an ImportError on this line.

I can workaround the issue on my end, but I thought I'd let you know that ImportErrors are technically possible when calling getattr on sys.modules entries.