import inspect
import builtins
savimp = builtins.__import__

def newimp(name, *x):
    caller = inspect.currentframe().f_back
print(name, caller.f_globals.get('__name__'))
return savimp(name, *x)
builtins.__import__ = newimp
How can I track python imports