Skip to content

Commit 38e9bbe

Browse files
authored
Merge pull request #13161 from roubert/running_under_virtualenv
2 parents 028c087 + 127134a commit 38e9bbe

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

news/13156.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Show the correct path to the interpreter also when it's a symlink in a venv in the pip upgrade prompt.

src/pip/_internal/utils/entrypoints.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def get_best_invocation_for_this_python() -> str:
7777

7878
# Try to use the basename, if it's the first executable.
7979
found_executable = shutil.which(exe_name)
80-
if found_executable and os.path.samefile(found_executable, exe):
80+
# Virtual environments often symlink to their parent Python binaries, but we don't
81+
# want to treat the Python binaries as equivalent when the environment's Python is
82+
# not on PATH (not activated). Thus, we don't follow symlinks.
83+
if found_executable and os.path.samestat(os.lstat(found_executable), os.lstat(exe)):
8184
return exe_name
8285

8386
# Use the full executable name, because we couldn't find something simpler.

0 commit comments

Comments
 (0)