How to get the current Python interpreter path from inside a Python script? [duplicate] How to get the current Python interpreter path from inside a Python script? [duplicate] python python

How to get the current Python interpreter path from inside a Python script? [duplicate]


The name of the interpreter is stored in the variable sys.executable


I found it by:

>>> 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'


Just for making sure:

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