1

My main script, main.py runs in python3. within it, I want to launch another script in some specified version of python.

import subprocess
pysh="/data/data/org.qpython.qpy/files/bin/qpython-android5.sh"
subprocess.call([pysh,'filetext.py'])

Question:

How can I use subprocess to open filetext.py in python2.x or 3.x interchangeably?

I have tried:

I have tried inputting several different arguments to no avail, such as:

os.system('python -2 -m filetext.txt')

or

subprocess.call(['py -2 filetext.txt'])

or

subprocess.call(['C:/Python27/python.exe filetext.txt'])

Any help would be immensely appreciated.

2 Answers 2

1

When I try almost the same thing, it seems to work as follows:

import subprocess

print(subprocess.call(["python2", "-c", "import sys; print sys.version"]))

When called from python3 this prints 2.7.5. This will depend of course on if the version of python you want to use is on the PATH, and if not, calling the binary with the full path.

Not sure if it's just a typo here, but I notice you said you wanted to run filetext.py, but you're passing filetext.txt in your examples.

If this doesn't work, I'd have to know more -- you say it doesn't work, but what exactly happens?

Sign up to request clarification or add additional context in comments.

Comments

1

Try this :

subprocess.call(['C:/Python27/python.exe', "filetext.txt"])

First you give the path to the executable you need, then the arguments in a different parameter.

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.