Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Python脚本中获取当前Python解释器路径?_Python_Path_Interpreter - Fatal编程技术网

如何从Python脚本中获取当前Python解释器路径?

如何从Python脚本中获取当前Python解释器路径?,python,path,interpreter,Python,Path,Interpreter,我想从带有子进程的Python脚本运行Python脚本,并且我希望对每个脚本使用相同的解释器 我正在使用virtualenv,所以我想做一些类似的事情: subprocess.Popen('%s script.py' % python_bin) 如何获取python_bin 在virtualenv外部应该是/usr/bin/python,在virtualenv中应该是/path/to/env/bin/python。解释器的名称存储在变量中,以确保: >>> import sy

我想从带有
子进程的Python脚本运行Python脚本,并且我希望对每个脚本使用相同的解释器

我正在使用virtualenv,所以我想做一些类似的事情:

subprocess.Popen('%s script.py' % python_bin)
如何获取python_bin


在virtualenv外部应该是
/usr/bin/python
,在virtualenv中应该是
/path/to/env/bin/python

解释器的名称存储在变量中,以确保:

>>> import sys
>>> sys.executable
'/usr/bin/python'
>>>
我是通过以下方式找到的:

>>> import sys           
>>> help(sys)
...

DATA
    __stderr__ = <open file '<stderr>', mode 'w' at 0x110029140>
    __stdin__ = <open file '<stdin>', mode 'r' at 0x110029030>
    __stdout__ = <open file '<stdout>', mode 'w' at 0x1100290b8>
    api_version = 1013
    argv = ['']
    builtin_module_names = ('__builtin__', '__main__', '_ast', '_codecs', ...
    byteorder = 'big'
    copyright = 'Copyright (c) 2001-2009 Python Software Foundati...ematis...
    dont_write_bytecode = False
    exc_value = TypeError('arg is a built-in module',)
    exec_prefix = '/usr/bin/../../opt/freeware'
    executable = '/usr/bin/python_64'
导入系统 >>>帮助(系统) ... 资料 __标准值= __标准偏差= __标准值= api_版本=1013 argv=[''] 内置模块名称=(“内置模块”、“主模块”、“ast”、“编解码器”、。。。 字节顺序='big' 版权='版权(c)2001-2009 Python软件基金会…ematis。。。 不要写入字节码=False exc_value=TypeError('arg是内置模块',) exec_prefix='/usr/bin/../../opt/freeware' 可执行文件='/usr/bin/python_64'
这对于嵌入式解释器不可靠,请使用
os.\uuuuu文件\uuuuuuu
因为(由提供)它实际上是
os上面的一个目录。\uuuuu文件\uuuuuu
有没有办法获取虚拟解释器的路径?