Skip to content

Commit

Permalink
Merge pull request #13161 from roubert/running_under_virtualenv
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Feb 3, 2025
2 parents 028c087 + 127134a commit 38e9bbe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/13156.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show the correct path to the interpreter also when it's a symlink in a venv in the pip upgrade prompt.
5 changes: 4 additions & 1 deletion src/pip/_internal/utils/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 38e9bbe

Please sign in to comment.