Assuming I have two Python modules and path_b is in the import path:
# file: path_b/my_module.py print \"I was imported from ???\" #file: path_a/app.py impo
There may be an easier way to do this, but this works:
import inspect print inspect.getframeinfo(inspect.getouterframes(inspect.currentframe())[1][0])[0]
Note that the path will be printed relative to the current working directory if it's a parent directory of the script location.