Eryk Sun added the comment:
subprocess.Popen calls CreateProcess on Windows, which searches for an
unqualified executable in the command line as follows:
1. The directory from which the application loaded.
2. The current directory for the parent process. (Starting with
Vista, the current directory is excluded from this search if
the environment variable NoDefaultCurrentDirectoryInExePath is
defined.)
3. The 32-bit Windows system directory. Use the GetSystemDirectory
function to get the path of this directory.
4. The 16-bit Windows system directory. There is no function that
obtains the path of this directory, but it is searched. The
name of this directory is System.
5. The Windows directory. Use the GetWindowsDirectory function to
get the path of this directory.
6. The directories that are listed in the PATH environment
variable.
Thus searching for "python" will always find "python.exe" from the application
directory.
To work around this, you can use shutil.which() to find python.exe on PATH and
pass it as the `executable` argument. For example:
os.environ['PATH'] = ';'.join([r'C:\Program Files\Python35', old_path])
python35 = shutil.which('python')
>>> print(python35)
C:\Program Files\Python35\python.EXE
>>> _ = subprocess.call('python -V')
Python 3.6.1
>>> _ = subprocess.call('python -V', executable=python35)
Python 3.5.2
----------
nosy: +eryksun
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue30783>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com