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
  • 4,036
  • 3
  • 21
  • 37

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
  • 355,277
  • 75
  • 744
  • 836
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,973
  • 16
  • 16