Python: importing all modules from a specified py filepath
thePyFilePath= "D:\\Test.py"; #Python 2.x import imp; allModules= imp.load_source("__all__", thePyFilePath); #Python 3.x from importlib.machinery import SourceFileLoader; SourceFileLoader("__all__",pyFilePath).load_module(); In Maya, both create a pyc file. 2.x creates a pyc file in the same folder as the py file. 3.x creates a pyc file in the __pycache__ folder.