Message296989
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 |
|
Date |
User |
Action |
Args |
2017-06-27 03:01:19 | eryksun | set | recipients:
+ eryksun, paul.moore, tim.golden, zach.ware, steve.dower, Ofekmeister |
2017-06-27 03:01:19 | eryksun | set | messageid: <1498532479.27.0.0905208774829.issue30783@psf.upfronthosting.co.za> |
2017-06-27 03:01:19 | eryksun | link | issue30783 messages |
2017-06-27 03:01:18 | eryksun | create | |
|