Speed up replace_imports
Fix for python 2.6