diff --git a/news/13156.bugfix.rst b/news/13156.bugfix.rst new file mode 100644 index 00000000000..e0553030070 --- /dev/null +++ b/news/13156.bugfix.rst @@ -0,0 +1 @@ +Show the correct path to the interpreter also when it's a symlink in a venv in the pip upgrade prompt. diff --git a/src/pip/_internal/utils/entrypoints.py b/src/pip/_internal/utils/entrypoints.py index 15013693854..696148c5097 100644 --- a/src/pip/_internal/utils/entrypoints.py +++ b/src/pip/_internal/utils/entrypoints.py @@ -77,7 +77,10 @@ def get_best_invocation_for_this_python() -> str: # Try to use the basename, if it's the first executable. found_executable = shutil.which(exe_name) - if found_executable and os.path.samefile(found_executable, exe): + # Virtual environments often symlink to their parent Python binaries, but we don't + # want to treat the Python binaries as equivalent when the environment's Python is + # not on PATH (not activated). Thus, we don't follow symlinks. + if found_executable and os.path.samestat(os.lstat(found_executable), os.lstat(exe)): return exe_name # Use the full executable name, because we couldn't find something simpler.