If I write program in python 2.7 and I want to run another script file with another python (2.6) how can I do this?
EDIT: I do this, because I need Django (which is installed in python 2.7) and I need some programs that are only available for python 2.6...
EDIT2: So I wrote simple script, that will be executed in python 2.6 and I will get results from it right in python 2.7
You have several options, but the most general concept is to use os.system to do your script execution.
os.system('python2.6 myscript.py')
os.system('myscript.py')
For this to work your script has to have the first line set to
#!/usr/bin/env python2.6
And your python2.6 executable needs to be in your PATH.
subprocess.Popen('myscript.py', subprocess.PIPE) #relying on shebang
subprocess.Popen(['/usr/bin/env', 'python2.6', 'myscript.py'], subprocess.PIPE) #manual interpreter selection
See http://docs.python.org/library/subprocess.html#subprocess.Popen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With