Author eryksun
Recipients Ofekmeister, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Date 2017-06-27.03:01:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1498532479.27.0.0905208774829.issue30783@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2017-06-27 03:01:19eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, Ofekmeister
2017-06-27 03:01:19eryksunsetmessageid: <1498532479.27.0.0905208774829.issue30783@psf.upfronthosting.co.za>
2017-06-27 03:01:19eryksunlinkissue30783 messages
2017-06-27 03:01:18eryksuncreate