How can I get the file path of a module imported in python. I am using Linux (if it matters).
Eg: if I am in my home dir and import a module, it should return back the full path of my home directory.
Modules and packages have a __file__
attribute that has its path information. If the module was imported relative to current working directory, you'll probably want to get its absolute path.
import os.path import my_module print(os.path.abspath(my_module.__file__))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With