我可以在python中找到python可执行文件的路径吗?

时间:2011-11-03 03:45:25

标签: python

  

可能重复:
  How to get current python interpreter path from inside a Python script?

标题几乎说明了。我想知道python中使用了哪个python可执行文件。像

这样的东西
Python 2.7.2 (default, Nov  1 2011, 03:31:17)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print <insert the code I'm after here>
/usr/local/bin/python2.7
>>>
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print <insert the code I'm after here>
/usr/bin/python2.6
>>>

你得到了照片

由于

2 个答案:

答案 0 :(得分:8)

你可以这样做:

>>> import sys
>>> print sys.executable
/usr/bin/python

如此处所述:How to get the python.exe location programmatically?

答案 1 :(得分:1)

为什么不使用bash where命令?

无论如何,这就是你要找的东西:

import sys
sys.executable