Python subprocess is running a different version of Python -
Python subprocess is running a different version of Python -
i'm trying create python script execute other python scripts, , works on scripts, fail when encounters print('anything', end=''). because subprocess running 2.7, rather 3.4. cannot life of me figure out how have subprocess run 3.4.
python 3.4.3 (v3.4.3:9b73f1c3e601, feb 24 2015, 22:43:06) [msc v.1600 32 bit (in tel)] on win32 type "help", "copyright", "credits" or "license" more information. >>> import sys >>> import subprocess >>> sys.version '3.4.3 (v3.4.3:9b73f1c3e601, feb 24 2015, 22:43:06) [msc v.1600 32 bit (intel)]' >>> results = subprocess.check_output('testprint.py', shell=true) >>> results b'2.7 (r27:82525, jul 4 2010, 07:43:08) [msc v.1500 64 bit (amd64)]\r\n' testprint.py this:
import sys print(sys.version) edit: , of course of study realize solution after posting question. modified code following:
path = r'c:\python34\python.exe' results = subprocess.check_output([path, 'testprint.py'], shell=true) now i'm passing in executable path script run through. still, love more elegant , permanent solution.
one solution do:
import sys import subprocess subprocess.call([sys.executable, 'testprint.py']) sys.executable location of python binary running code executing. note reason shell=true launches python binary without arguments on sys.argv, either omit option, utilize string or shlex.quote. same solution, executable position not hard-coded.
python-3.x subprocess
Comments
Post a Comment