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.x恩mypackagemyscript.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.
- 与环境变量(如bash的PATH变量)中的第一个python相反,它是否总是检索用于安装的python?
- faik,它是用于运行访问sys.executable的脚本的解释器的绝对路径,不使用PATH。使用的描述在sys文档中。
看看sys.version或sys.version_info。
- 这告诉了我版本,但我需要知道它在系统中的路径,以便我可以从myscript.py调用它。