user7073454 user7073454 - 27 days ago 7
Python Question

python -find which library is currently executed

I need to find out the path for a particular library in my script.

I tried using :

os.path.dirname(MODULE.__file__),


but it gives an attribute error:

"type object 'MODULE' has no attribute '__file__'."


Is there any other way to find the path for a particular module? I do not want to use
sys.path
as it gives the list of all the libraries.

Answer

Actually my code was something like : from <module> import blah

I was trying to find the module path using : os.path.dirname(module.__file__) It gave an error saying "module" does not exist. So I did : import module and then from <module> import blah Then it worked !!