anchor.diff:  
   :# Get a list of all python.exe executables
   :GetAllPythonExe %1=LISTNAME
  -setlocal EnableDelayedExpansion
  -set "SEARCHDRIVES=C:"		&:# List of drives where to search for python.exe.
  -if not "%HOMEDRIVE%"=="C:" set "SEARCHDRIVES=%HOMEDRIVE% %SEARCHDRIVES%" &:# Prepend the home drive, if it's different.
  -for /f "tokens=1" %%d in ('net use ^| findstr /C:"\\vmware-host\Shared Folders\\"') do ( :# And append VM host drives, if any.
  -  if exist "%%d%ProgramFiles:~2%" set "SEARCHDRIVES=!SEARCHDRIVES! %%d"
  -)
  -%ECHOVARS.D% SEARCHDRIVES
  -set "SHORT_LIST=" &:# List of instances found. Used to avoid reporting one twice.
  +%FUNCTION% EnableDelayedExpansion
   set "LIST=" &:# List of instances found.
  -:# List first the default instance
  -call :GetPythonExe PYTHON
  -if defined PYTHON (
  -  for %%p in ("%PYTHON%") do call :lappend SHORT_LIST "%%~sp"
  -  call :lappend LIST "%PYTHON%"
  -)
  -:# Then look for other instances in well known places
  -for %%d in (%SEARCHDRIVES%) do (
  +
  +:# First list the default instance
  +call :GetPythonExe DEFAULT
  +set "SHORT_DEFAULT=" &:# Short version of the same, used to avoid reporting it twice.
  +if defined DEFAULT for %%p in ("!DEFAULT!") do (
  +  set "SHORT_DEFAULT=%%~sp"
  +  call :lappend LIST "%%~fp"
  +)
  +
  +:# Then list py.exe if it's not the default
  +if defined DEFAULT for %%p in ("%DEFAULT%") do if not "%%~nxp"=="py.exe" (
  +  for %%x in (py.exe) do set "PY=%%~$PATH:x"
  +  if defined PY for %%p in ("!PY!") do (
  +    call :lappend LIST "%%~fp"
  +  )
  +)
  +
  +:# Then list all instances that match the requested criteria
  +call :GetAllPythonDirs ALL_DIRS
  +for %%d in (%ALL_DIRS%) do (
  +  for %%p in ("%%~d\python.exe") do (
  +    if not "%%~sp"=="%SHORT_DEFAULT%" (
  +      call :lappend LIST "%%~fp"
  +    )
  +  )
  +)
  +
  +endlocal & set %~1=%LIST%
  +%ECHOVARS.D% %~1
  +exit /b
  +
  +:# Get a list of all python.exe installation directories in well known places
  +:GetAllPythonDirs %1=LISTNAME
  +%FUNCTION% EnableDelayedExpansion
  +set "LISTNAME=%~1"
  +set "DRIVES=C:"		&:# List of drives where to search for python.exe
  +if not "%HOMEDRIVE%"=="C:" set "DRIVES=%HOMEDRIVE% %DRIVES%" &:# Prepend the home drive, if it's different
  +for /f "tokens=1" %%d in ('net use ^| findstr /C:"\\vmware-host\Shared Folders\\"') do ( :# And append VM host drives, if any
  +  if exist "%%d%ProgramFiles:~2%" set "DRIVES=!DRIVES! %%d"
  +)
  +%ECHOVARS.D% DRIVES
  +set "LIST="
  +if not defined ProgramFiles(x86) set "ProgramFiles(x86)=%ProgramFiles% (x86)" &:# For x86 VMs searching on amd64 hosts
  +for %%d in (%DRIVES%) do (
     rem :# The default install dir is %LOCALAPPDATA%\Programs\Python\Python%VER% for the current user,
     rem :# Or %ProgramFiles%\Python%VER% or %ProgramFiles(x86)%\Python%VER% for all users.
     for %%p in ("" "%ProgramFiles:~2%" "%ProgramFiles(x86):~2%" "%LOCALAPPDATA:~2%\Programs") do (
       for %%y in ("Python" "Python\Python" "Microsoft Visual Studio\Shared\Python") do (
         for /d %%b in ("%%d%%~p\%%~y*") do (
  -        %ECHO.D% :# Looking in %%b
  +	%ECHO.D% :# Looking in %%~b
   	for %%x in ("%%~b\python.exe") do if exist "%%~x" (
  -	  set "FOUND=" &:# Avoid duplications, for example with the default instance
  -	  for %%s in (!SHORT_LIST!) do if not defined FOUND if /i "%%~sx"=="%%~s" set "FOUND=1"
  -	  if not defined FOUND call :lappend SHORT_LIST "%%~sx" & call :lappend LIST "%%~fx"
  +	  if defined LISTNAME (
  +	    call :lappend LIST "%%~b"
  +	  ) else (
  +	    set "B=%%~b"
  +	    echo !B!
  +	  )
   	)
         )
       )
     )
   )
  -endlocal & set %~1=%LIST%
  -exit /b
  -
  -:# Get the corresponding pip.exe executable if it exists
  -:GetPythonPipExe %1=PYTHON %2=VARNAME
  -set "%~2="
  -for %%p in ("%~dp1Scripts\pip.exe") do if exist %%p set "%~2=%%~p"  
  -exit /b
  -
  -:# Get a list of all pip.exe executables
  -:GetAllPipExe %1=LISTNAME
  -setlocal DisableDelayedExpansion
  -call :GetAllPythonExe PLIST
  -set "LIST="
  -for %%e in (%PLIST%) do (
  -  call :GetPythonPipExe %%e PIP
  -  if defined PIP call call :lappend LIST "%%PIP%%"
  -)
  -endlocal & set %~1=%LIST%
  -exit /b
  -
  -:# List pip.exe instances
  -:list
  -setlocal EnableDelayedExpansion
  -call :GetAllPipExe LIST
  +if defined LISTNAME (
  +  set SET_RESULT=set %LISTNAME%=%LIST%
  +  %ECHO.D% !SET_RESULT!
  +) else (
  +  set SET_RESULT=rem
  +)
  +endlocal & %SET_RESULT%
  +exit /b
  +
  +:# Enumerate pip.exe instances
  +:EnumPip %1=Optional instance to search; %2=Output variable name
  +%FUNCTION% EnableDelayedExpansion
  +call :GetAllPythonExe ALL_PYTHON
  +set "WANT_INDEX=%~1"
  +set "OUTVAR=%~2"
  +set "FOUND="
   set "N=0"
  -for %%e in (!LIST!) do (
  -  echo #!N! %%~e
  -  set /a "N+=1"
  -)
  -endlocal
  -exit /b
  +set ^"PY_VER_ARCH_CMD=import sys, os; print (sys.version.split()[0]+\" \"+os.environ[\"PROCESSOR_ARCHITECTURE\"])^"
  +for %%e in (!ALL_PYTHON!) do (
  +  set "PY_VER=" & set "PY_ARCH="
  +  for /f "tokens=1,2" %%v in ('^"%%e -c "!PY_VER_ARCH_CMD!" 2^>NUL^"') do set "PY_VER=%%v" & set "PY_ARCH=%%w"
  +  if defined PY_VER if defined PY_ARCH (
  +    set "PY_DIR=%%~dpe" & set "PY_DIR=!PY_DIR:~0,-1!"
  +    %ECHOVARS.D% PY_VER PY_ARCH PY_DIR
  +    if exist "!PY_DIR!\py.exe" if not exist "!PY_DIR!\Scripts\pip.exe" (
  +      :# Find the actual python instance that py.exe runs by default
  +      for /f "delims=" %%p in ('^""!PY_DIR!\py.exe" -c "import sys; print (sys.executable)"^"') do (
  +      	set "PY_DIR=%%~dpp" & set "PY_DIR=!PY_DIR:~0,-1!"
  +      )
  +    )
  +    set "FOUNDX="
  +    :# Python 2.7 installs a pip.bat script, but no pip.exe command
  +    :# Python 3.5 installs a pip3.bat script, but no pip.exe or pip.bat
  +    for %%p in (pip.exe pip.bat pip3.bat) do (
  +      if not defined FOUNDX for %%p in ("!PY_DIR!\Scripts\%%p") do if exist %%p (
  +      	set "FOUNDX=1"
  +	set "INDEX_=!N!       "
  +	set "PY_VER_=!PY_VER!       "
  +	set "PY_ARCH_=!PY_ARCH!       "
  +	if defined OUTVAR (
  +	  if "!N!"=="!WANT_INDEX!" (
  +	    set "FOUND=%%~p"
  +	    goto :EnumPip.exit
  +	  )
  +	) else (
  +	  echo #!INDEX_:~0,3! !PY_VER_:~0,8! !PY_ARCH_:~0,7! %%~p
  +	)
  +      )
  +    )
  +    set /a "N+=1"
  +  )
  +)
  +:EnumPip.exit
  +set "SET_VAR=rem"
  +if defined OUTVAR set ^"SET_VAR=set "%OUTVAR%=%FOUND%"^"
  +endlocal & %SET_VAR% & %ECHOVARS.D% %OUTVAR%
  +exit /b 0
   
   :#----------------------------------------------------------------------------#
   :# Main routine
  
positive.code: :get_arg
  if [%1]==[] goto :go
  set "ARG=%~1"
  if "%ARG%"=="-?" call :usage & set "PYARGS=-h" & goto :go
  if "%ARG%"=="--" goto :next_pyarg &:# All remaining arguments are for pip.exe
  if "%ARG%"=="-#" set "PY#=%~2" & shift & goto :next_arg
  if "%ARG%"=="-d" call :debug.on & goto :next_arg
  if "%ARG:~0,1%"=="#" set "PY#=%ARG:~1%" & goto :next_arg
  if "%ARG%"=="-l" call :list & exit /b
  if "%ARG%"=="-V" (echo %SCRIPT% %VERSION%) & set "PYARGS=-V" & goto :go
  if "%ARG%"=="-X" set "EXEC=echo" & goto :next_arg
  :get_pyarg
  if [%1]==[] goto :go
  call :lappend PYARGS %1
  :next_pyarg
  shift
  goto :get_pyarg
  
  :go
  
  :# Get the Nth Pip instance
  set "PIP="
  if %PY#%==0 ( :# Performance optimization for instance #0
    call :GetPythonExe PYTHON
    if defined PYTHON call call :GetPythonPipExe "%%PYTHON%%" PIP
  )
  if not defined PIP ( :# For %PY#% > 0, or if the above search for #0 failed
    call :GetAllPipExe LIST
    call :lindex LIST %PY#% PIP
  )
  if not defined PIP (
    echo %SCRIPT%: Error: No pip command found
    exit /b 1
  )
  %EXEC% "%PIP%" %PYARGS%
  
negative.code: 
  :main
  set "EXEC="
  set "PIPARGS="
  if not defined PY# set "PY#=0"
  
  goto :get_arg
  