Some of my code use the now deprecated imp package to find a module
toolboxFile, toolboxPath, toolboxDescription = imp.find_module(\"Tools\")
According to Python official documentation in this page imp
find_module
Deprecated since version 3.3 Use importlib.util.find_spec()
instead unless Python 3.3 compatibility is required, in which case use importlib.find_loader()
.
Use importlib.util.find_spec("Tools")
for find spec for more information you can see this link.
And use importlib.find_loader("Tools")
for find loader more information
EDIT:
sample code
import importlib
import importlib.util
import sys
name="test"
moduledir="d:\\dirtest"
# this is optional set that if you what load from specific directory
try:
spec = importlib.util.find_spec(name,moduledir)
if spec is None:
print("Import error 0: " + " module not found")
sys.exit(0)
toolbox = spec.loader.load_module()
except (ValueError, ImportError) as msg:
print("Import error 3: "+str(msg))
sys.exit(0)
print("load module")