def activate(self, force=False):
        """Have the interpreter use this import state, saving the old."""
        if self._saved is not None and not force:
            raise TypeError("Already activated; try using a copy")

        self._saved = _ImportState(
                sys.modules.copy(),  # saving away the contents
                sys.meta_path,
                sys.path,
                sys.path_hooks,
                sys.path_importer_cache,
                )

        #sys.modules = self.modules
        sys.meta_path = self.meta_path
        sys.path = self.path
        sys.path_hooks = self.meta_path
        sys.path_importer_cache = self.path_importer_cache

        # accommodate sys.module's quirkiness
        sys.modules.clear()
        sys.modules.update(self.modules)
Have the interpreter use this import state, saving the old.
recipes/Python/578107_Tracking_Manipulating_PythImport/recipe-578107.py