I am creating a wrapper around a few python scripts and have run into a slight issue when there are multiple versions of python installed on the computer. For example on my Mac there is python 2.7 accessible via "python" at the command line and python 3.4 available "python3". Is there anyway to determine how the current python instance was started so that I can be sure the subprocess will be using the right version?
import subprocess
def main():
pythonCommand = determineCommand() #What is python install as on this computer
argArray = [pythonCommand, "test.py"] #requires python 3.4
subprocess.call(argArray)
#What I need to figure out
def determineCommand():
#If Some Check
return "python3"
#Else some other check
return "python"
#else something weird
return "python34"
#and so on
if __name__ == "__main__":
main()
The above code will not execute properly on my computer but on a computer with only python 3.4 installed it works fine. Changing the argArray to use python3 works on my computer but breaks it on others.