Since I am using Python 3.6, I can answer from that perspective. You can refer to the following code to solve your problem
from modulefinder import ModuleFinder
finder = ModuleFinder()
finder.run_script("script.py")
for name, mod in finder.modules.items():
print(name)
This code will print all modules loaded by script.py.