@@ -310,7 +310,10 @@ def search_up(prefix, *landmarks, test=isfile):
310
310
# and should not affect base_executable.
311
311
base_executable = f"{ dirname (library )} /bin/python{ VERSION_MAJOR } .{ VERSION_MINOR } "
312
312
else :
313
- base_executable = executable
313
+ # Use the real executable as our base, or argv[0] otherwise
314
+ # (on Windows, argv[0] is likely to be ENV___PYVENV_LAUNCHER__; on
315
+ # other platforms, real_executable is likely to be empty)
316
+ base_executable = real_executable or executable
314
317
315
318
if not real_executable :
316
319
real_executable = base_executable
@@ -408,13 +411,14 @@ def search_up(prefix, *landmarks, test=isfile):
408
411
if not real_executable :
409
412
real_executable = base_executable
410
413
411
- try :
412
- real_executable = realpath (real_executable )
413
- except OSError as ex :
414
- # Only warn if the file actually exists and was unresolvable
415
- # Otherwise users who specify a fake executable may get spurious warnings.
416
- if isfile (real_executable ):
417
- warn (f'Failed to find real location of { base_executable } ' )
414
+ if real_executable :
415
+ try :
416
+ real_executable = realpath (real_executable )
417
+ except OSError as ex :
418
+ # Only warn if the file actually exists and was unresolvable
419
+ # Otherwise users who specify a fake executable may get spurious warnings.
420
+ if isfile (real_executable ):
421
+ warn (f'Failed to find real location of { base_executable } ' )
418
422
419
423
if not executable_dir and os_name == 'darwin' and library :
420
424
# QUIRK: macOS checks adjacent to its library early
@@ -427,12 +431,12 @@ def search_up(prefix, *landmarks, test=isfile):
427
431
428
432
# If we do not have the executable's directory, we can calculate it.
429
433
# This is the directory used to find prefix/exec_prefix if necessary.
430
- if not executable_dir :
434
+ if not executable_dir and real_executable :
431
435
executable_dir = real_executable_dir = dirname (real_executable )
432
436
433
437
# If we do not have the real executable's directory, we calculate it.
434
438
# This is the directory used to detect build layouts.
435
- if not real_executable_dir :
439
+ if not real_executable_dir and real_executable :
436
440
real_executable_dir = dirname (real_executable )
437
441
438
442
# ******************************************************************************
0 commit comments