Check if Python Package is installed

If you mean a python script, just do something like this: Python 3.3+ use sys.modules and find_spec: import importlib.util import sys # For illustrative purposes. name=”itertools” if name in sys.modules: print(f”{name!r} already in sys.modules”) elif (spec := importlib.util.find_spec(name)) is not None: # If you choose to perform the actual import … module = importlib.util.module_from_spec(spec) sys.modules[name] … Read more