Backport of shutil.which