diff --git a/news/11309.bugfix.rst b/news/11309.bugfix.rst new file mode 100644 index 00000000000..9ee54057da4 --- /dev/null +++ b/news/11309.bugfix.rst @@ -0,0 +1 @@ +Ensure that the candidate ``pip`` executable exists, when checking for a new version of pip. diff --git a/src/pip/_internal/utils/entrypoints.py b/src/pip/_internal/utils/entrypoints.py index f292c64045b..15013693854 100644 --- a/src/pip/_internal/utils/entrypoints.py +++ b/src/pip/_internal/utils/entrypoints.py @@ -55,9 +55,14 @@ def get_best_invocation_for_this_pip() -> str: if exe_are_in_PATH: for exe_name in _EXECUTABLE_NAMES: found_executable = shutil.which(exe_name) - if found_executable and os.path.samefile( - found_executable, - os.path.join(binary_prefix, exe_name), + binary_executable = os.path.join(binary_prefix, exe_name) + if ( + found_executable + and os.path.exists(binary_executable) + and os.path.samefile( + found_executable, + binary_executable, + ) ): return exe_name