def interpreter_path(self):
'''
Returns the path for python interpreter, assuming it can be found. Because of various factors (inlcuding ablity to override) this may not be accurate.
'''
if not self.__interpreter_path:
#first try sys.executable--this is reliable most of the time but doesn't work when python is embedded, ex. using wsgi mod for web server
if "python" in os.path.basename(sys.executable):
self.__interpreter_path = sys.executable
#second try sys.prefix and common executable names
else:
possible_path = os.path.join(sys.prefix, "python.exe")
if os.path.exists(possible_path):
self.__interpreter_path = possible_path
possible_path = os.path.join(sys.prefix, "bin", "python")
if os.path.exists(possible_path):
self.__interpreter_path = possible_path
#other options to consider:
#look at some library paths, such as os.__file__, use system path to find python executable that uses that library
#use shell and let it find python. Ex. which python
return self.__interpreter_path
评论列表
文章目录