diff --git a/news/11387.bugfix.rst b/news/11387.bugfix.rst new file mode 100644 index 00000000000..285a78ef8eb --- /dev/null +++ b/news/11387.bugfix.rst @@ -0,0 +1 @@ +Adding a check to verify that pip exists in th binary_prefix path prior to checking if it matches the pip found using shutil diff --git a/src/pip/_internal/utils/entrypoints.py b/src/pip/_internal/utils/entrypoints.py index f292c64045b..0c319aa8542 100644 --- a/src/pip/_internal/utils/entrypoints.py +++ b/src/pip/_internal/utils/entrypoints.py @@ -55,9 +55,10 @@ 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( + bin_exe_path = os.path.join(binary_prefix, exe_name) + if found_executable and os.path.isfile(bin_exe_path) and os.path.samefile( found_executable, - os.path.join(binary_prefix, exe_name), + bin_exe_path, ): return exe_name