import imp modname = "imp-test-mod" f, p, d = imp.find_module(modname) try: mod = imp.load_module(modname, f, p, d) finally: f.close() print('successfully loaded {}'.format(modname))