importimportlib.utilimportsys# For illustrative purposes.name='itertools'ifnameinsys.modules:print(f"{name!r} already in sys.modules")elif(spec:=importlib.util.find_spec(name))isnotNone:# If you chose to perform the actual import ...module=importlib.util.module_from_spec(spec)sys.modules[name]=modulespec.loader.exec_module(module)print(f"{name!r} has been imported")else:print(f"can't find the {name!r} module")