简体   繁体   中英

How to run python script from python with different interpreter version?

How to run my script with one version of python from script with another version of python? Also, is there a way to catch all outputs of my script and print it?

So you want to theoretically run say a script with python2 from a script running with python3? (Or something like that, I'm not really sure) If so I would use subprocess. You can find more information on that https://docs.python.org/2/library/subprocess.html and How do I execute a program from python? os.system fails due to spaces in path .

#my python3 script
import subprocess
subprocess.call(["python2", "python2scipt.py"])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM