找出用于安装当前包的Python?

Finding out the Python used to install the current package?

本问题已经有最佳答案,请猛点这里访问。

is there to find以编程方式安装的Python版本which was used to the current包装?P></

如果你有一个mypackage包装和EN在ITS setup.pyhas something like:P></

1
scripts = ["myscript.py"]

想与easy_installinstall the包装或pip使用Python Python是2.x版本:P></

1
/usr/local/bin/python2.x setup.py install

那么你怎么能在myscript.py,find out that was that was used to /usr/local/bin/python2.xmypackagemyscript.pyas to install some from other Python版本opposed available on the系统?我知道我不只是茶茶全路径和版本信息,因为我想在我的/usr/local/bin/python2.x脚本使用。P></


使用sys.executable

A string giving the absolute path of the executable binary for the
Python interpreter, on systems where this makes sense. If Python is
unable to retrieve the real path to its executable, sys.executable
will be an empty string or None.


看看sys.versionsys.version_info