Python 2.6 and 3 compatibility.

Loop over a copy of sys.modules as inspect may load some new ones,
and catch an AttributeError raised by Django copy of six when an
import fails.