@@ -229,9 +229,10 @@ def search_up(prefix, *landmarks, test=isfile):
229229
230230pythonpath = config .get ('module_search_paths' )
231231pythonpath_was_set = config .get ('module_search_paths_set' )
232+ stdlib_dir = config .get ('stdlib_dir' )
233+ stdlib_dir_was_set_in_config = bool (stdlib_dir )
232234
233235real_executable_dir = None
234- stdlib_dir = None
235236platstdlib_dir = None
236237
237238# ******************************************************************************
@@ -507,11 +508,12 @@ def search_up(prefix, *landmarks, test=isfile):
507508 build_stdlib_prefix = build_prefix
508509 else :
509510 build_stdlib_prefix = search_up (build_prefix , * BUILDSTDLIB_LANDMARKS )
510- # Always use the build prefix for stdlib
511- if build_stdlib_prefix :
512- stdlib_dir = joinpath (build_stdlib_prefix , 'Lib' )
513- else :
514- stdlib_dir = joinpath (build_prefix , 'Lib' )
511+ # Use the build prefix for stdlib when not explicitly set
512+ if not stdlib_dir_was_set_in_config :
513+ if build_stdlib_prefix :
514+ stdlib_dir = joinpath (build_stdlib_prefix , 'Lib' )
515+ else :
516+ stdlib_dir = joinpath (build_prefix , 'Lib' )
515517 # Only use the build prefix for prefix if it hasn't already been set
516518 if not prefix :
517519 prefix = build_stdlib_prefix
@@ -543,8 +545,9 @@ def search_up(prefix, *landmarks, test=isfile):
543545 prefix , had_delim , exec_prefix = home .partition (DELIM )
544546 if not had_delim :
545547 exec_prefix = prefix
546- # Reset the standard library directory if it was already set
547- stdlib_dir = None
548+ # Reset the standard library directory if it was not explicitly set
549+ if not stdlib_dir_was_set_in_config :
550+ stdlib_dir = None
548551
549552
550553 # First try to detect prefix by looking alongside our runtime library, if known
@@ -560,7 +563,8 @@ def search_up(prefix, *landmarks, test=isfile):
560563 if STDLIB_SUBDIR and STDLIB_LANDMARKS and not prefix :
561564 if any (isfile (joinpath (library_dir , f )) for f in STDLIB_LANDMARKS ):
562565 prefix = library_dir
563- stdlib_dir = joinpath (prefix , STDLIB_SUBDIR )
566+ if not stdlib_dir_was_set_in_config :
567+ stdlib_dir = joinpath (prefix , STDLIB_SUBDIR )
564568
565569
566570 # Detect prefix by looking for zip file
@@ -571,7 +575,7 @@ def search_up(prefix, *landmarks, test=isfile):
571575 prefix = executable_dir
572576 else :
573577 prefix = search_up (executable_dir , ZIP_LANDMARK )
574- if prefix :
578+ if prefix and not stdlib_dir_was_set_in_config :
575579 stdlib_dir = joinpath (prefix , STDLIB_SUBDIR )
576580 if not isdir (stdlib_dir ):
577581 stdlib_dir = None
0 commit comments