在*nix系统中,可以使用
有没有一种简单的方法可以找出PYTHONPATH中模块的位置。类似于以下内容:
which
命令来查找命令的完整路径。例如:$ which python
/usr/bin/python
或者使用whereis
命令来显示给定命令的所有可能位置。
$ whereis python
python: /bin/python.exe /bin/python2.5-config /usr/bin/python.exe /usr/bin/python2.5-config /lib/python2.4 /lib/python2.5 /usr/lib/python2.4 /usr/lib/python2.5 /usr/include/python2.4 /usr/include/python2.5 /usr/share/man/man1/python.1
有没有一种简单的方法可以找出PYTHONPATH中模块的位置。类似于以下内容:
>>> which (sys)
'c:\\Python25\Lib\site-packages'
__file__
属性吗?例如:>>> import sys >>> sys.__file__ Traceback (most recent call last): File "", line 1, in
AttributeError: 'module' object has no attribute '__file__'
>>> import os
>>> os.__file__
'C:\\Python25\\lib\\os.pyc'
- Boris Goreliksys
无效。 - Mike Dinsdalesys
无效,因为sys
根本不来自文件:它是一个内置模块。因此,对于which(sys)
没有明智的答案。 - bobince