import sys
import os

def getPythonExecutable():
	if os.environ.has_key("CCP4MG"):
		if os.path.exists(os.path.join(sys.prefix,"python.exe")):
			pyexe = os.path.join(sys.prefix,"python.exe")
		elif os.path.exists(os.path.join(os.environ["CCP4MG"],"pythondist","bin","python")):
			pyexe = os.path.join(os.environ["CCP4MG"],"pythondist","bin","python")
		elif  os.path.exists(os.path.join(os.environ["CCP4MG"],"bin","QtMG")):
			pyexe = os.path.join(os.environ["CCP4MG"],"bin","QtMG")
		elif  os.path.exists(os.path.join(os.environ["CCP4MG"],"Frameworks","Python.framework","Versions","Current","bin","python")):
			pyexe = os.path.join(os.environ["CCP4MG"],"Frameworks","Python.framework","Versions","Current","bin","python")
		else:
			pyexe = "python"
	else:
			pyexe = "python"
	return pyexe

if __name__ =="__main__":
	print getPythonExecutable()
