Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I'm running the following piece of code:
p = subprocess.getoutput("python ./file.py")
How do I ensure the python version used is python3?
Thanks!
p=subprocess.check_output('python ./file.py < input.txt', shell=True)
Assuming your controlling script is running in python 3, and thus you are simply wanting to run a subprocess of an identical version of python, then try:
import sys p = subprocess.getoutput("'{}' ./file.py < input.txt".format(sys.executable))
Add a comment
The obvious way to ensure python 3.x is used is:
p = subprocess.getoutput("python3 ./file.py < input.txt")
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
p=subprocess.check_output('python ./file.py < input.txt', shell=True)