@@ -640,11 +640,18 @@ def search_up(prefix, *landmarks, test=isfile):
640
640
641
641
642
642
# For a venv, update the main prefix/exec_prefix but leave the base ones unchanged
643
- # XXX: We currently do not update prefix here, but it happens in site.py
644
- #if venv_prefix:
645
- # base_prefix = prefix
646
- # base_exec_prefix = exec_prefix
647
- # prefix = exec_prefix = venv_prefix
643
+ if venv_prefix :
644
+ base_prefix = prefix
645
+ base_exec_prefix = exec_prefix
646
+ prefix = exec_prefix = venv_prefix
647
+
648
+
649
+ # After calculating prefix and exec_prefix, use their values for base_prefix and
650
+ # base_exec_prefix if they haven't been set.
651
+ if not base_prefix :
652
+ base_prefix = prefix
653
+ if not base_exec_prefix :
654
+ base_exec_prefix = exec_prefix
648
655
649
656
650
657
# ******************************************************************************
@@ -679,7 +686,7 @@ def search_up(prefix, *landmarks, test=isfile):
679
686
# QUIRK: POSIX uses the default prefix when in the build directory
680
687
pythonpath .append (joinpath (PREFIX , ZIP_LANDMARK ))
681
688
else :
682
- pythonpath .append (joinpath (prefix , ZIP_LANDMARK ))
689
+ pythonpath .append (joinpath (base_prefix , ZIP_LANDMARK ))
683
690
684
691
if os_name == 'nt' and use_environment and winreg :
685
692
# QUIRK: Windows also lists paths in the registry. Paths are stored
@@ -714,13 +721,13 @@ def search_up(prefix, *landmarks, test=isfile):
714
721
# Then add any entries compiled into the PYTHONPATH macro.
715
722
if PYTHONPATH :
716
723
for p in PYTHONPATH .split (DELIM ):
717
- pythonpath .append (joinpath (prefix , p ))
724
+ pythonpath .append (joinpath (base_prefix , p ))
718
725
719
726
# Then add stdlib_dir and platstdlib_dir
720
- if not stdlib_dir and prefix :
721
- stdlib_dir = joinpath (prefix , STDLIB_SUBDIR )
722
- if not platstdlib_dir and exec_prefix :
723
- platstdlib_dir = joinpath (exec_prefix , PLATSTDLIB_LANDMARK )
727
+ if not stdlib_dir and base_prefix :
728
+ stdlib_dir = joinpath (base_prefix , STDLIB_SUBDIR )
729
+ if not platstdlib_dir and base_exec_prefix :
730
+ platstdlib_dir = joinpath (base_exec_prefix , PLATSTDLIB_LANDMARK )
724
731
725
732
if os_name == 'nt' :
726
733
# QUIRK: Windows generates paths differently
@@ -750,7 +757,8 @@ def search_up(prefix, *landmarks, test=isfile):
750
757
751
758
# QUIRK: Non-Windows replaces prefix/exec_prefix with defaults when running
752
759
# in build directory. This happens after pythonpath calculation.
753
- if os_name != 'nt' and build_prefix :
760
+ # Virtual environments using the build directory Python still keep their prefix.
761
+ if not venv_prefix and os_name != 'nt' and build_prefix :
754
762
prefix = config .get ('prefix' ) or PREFIX
755
763
exec_prefix = config .get ('exec_prefix' ) or EXEC_PREFIX or prefix
756
764
@@ -788,8 +796,8 @@ def search_up(prefix, *landmarks, test=isfile):
788
796
config ['base_executable' ] = base_executable
789
797
config ['prefix' ] = prefix
790
798
config ['exec_prefix' ] = exec_prefix
791
- config ['base_prefix' ] = base_prefix or prefix
792
- config ['base_exec_prefix' ] = base_exec_prefix or exec_prefix
799
+ config ['base_prefix' ] = base_prefix
800
+ config ['base_exec_prefix' ] = base_exec_prefix
793
801
794
802
config ['platlibdir' ] = platlibdir
795
803
# test_embed expects empty strings, not None
0 commit comments