【发布时间】:2012-03-09 22:49:33
【问题描述】:
我想在运行时或在 ipython 中获得此信息。例如,
import matplotlib
如果我有多个版本或者我只想知道文件的位置,我如何知道使用了哪个 matplotlib.py。
谢谢
【问题讨论】:
-
我想你其实是想找
__version__,但不知道是不是为matplotlib定义的。
我想在运行时或在 ipython 中获得此信息。例如,
import matplotlib
如果我有多个版本或者我只想知道文件的位置,我如何知道使用了哪个 matplotlib.py。
谢谢
【问题讨论】:
__version__,但不知道是不是为matplotlib定义的。
检查模块的__file__ 属性。
In [1]: import matplotlib
In [2]: matplotlib.__file__
Out[2]: '/usr/lib/pymodules/python2.7/matplotlib/__init__.pyc'
(也适用于普通 Python。)
【讨论】:
matplotlib,给你<module 'matplotlib' from '/usr/lib/pymodules/python2.7/matplotlib/__init__.pyc'>
您可以使用sys.modules 找到它的路径。
如:
import math
import sys
print sys.modules['math']
【讨论】: