1

I would like to have this info during run-time or in ipython. For example,

import matplotlib

How do I know which matplotlib.py is used if I have multiple versions or I just want to know where the file located.

Thanks

Yan Zhu
  • 3,640
  • 3
  • 19
  • 34

2 Answers2

4

Inspect the module's __file__ attribute.

In [1]: import matplotlib

In [2]: matplotlib.__file__
Out[2]: '/usr/lib/pymodules/python2.7/matplotlib/__init__.pyc'

(Works in vanilla Python too.)

Fred Foo
  • 342,876
  • 71
  • 713
  • 819
2

You can use the sys.modules to find the path of it.

Such as:

import math
import sys
print sys.modules['math']
veiset
  • 1,903
  • 16
  • 16