importlib — The implementation of import — Python 3.10.3 ...
docs.python.org › 3 › libraryMar 21, 2022 · To import a Python source file directly, use the following recipe (Python 3.5 and newer only): import importlib.util import sys # For illustrative purposes. import tokenize file_path = tokenize . __file__ module_name = tokenize . __name__ spec = importlib . util . spec_from_file_location ( module_name , file_path ) module = importlib . util . module_from_spec ( spec ) sys . modules [ module_name ] = module spec . loader . exec_module ( module )