2

Trying to use shutil.which() to determine if git is installed. From the docs, I see which() on Windows should use PATHEXT to know which file extensions to append when searching. However the following occurs when using the interpreter:

>>> import os
>>> import shutil
>>> os.getenv('PATHEXT')
'.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;'
>>> shutil.which('git')
>>> shutil.which('git.exe')
'C:\\Program Files\\Git\\cmd\\git.exe'

This is in a virtual environment created using VirtualEnv Wrapper in D:\Envs if that makes any difference.

  • 1
    Try changing `PATHEXT` to lower case, e.g. `os.environ['PATHEXT'] = os.environ['PATHEXT'].lower()`. If that works, apparently the directory is flagged as case sensitive, which is possible with NTFS in Windows 10. – Eryk Sun May 31 '19 at 19:42
  • shutil deals with the path extension on it's own. I only included it here to show what gets returned (and that .exe is indeed present). See [the docs](https://docs.python.org/3.7/library/shutil.html#shutil.which) – cafeclimber Jun 01 '19 at 16:11
  • 2
    `shutil.which('git')` will look for "git.EXE" in `PATH`. If a directory is case sensitive, then "git.EXE" will not match a file named "git.exe" in the directory. I don't know whether this is your problem, but since NTFS started supporting case-sensitive directories, I have come across problems with `PATHEXT`, so this was the first workaround that sprang to mind, and presently the only thing that makes any sense to me given the implementation of `shutil.which`. – Eryk Sun Jun 01 '19 at 16:24

1 Answers1

0

Remove the trailing ; from your PATHEXT environment variable. It seems shutil.which() gets confused by this and interprets an empty string as a valid file extension, and therefore doesn't try to append any of the file extensions.

More details here: "jupyter-kernelspec" not found while installing iqsharp however it exists on PATH

Ryan Shaffer
  • 405
  • 3
  • 12