diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 169ae5cb0a06eb..f93301da88863c 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1264,6 +1264,17 @@ def test_init_setpythonhome(self): # Because we are specifying 'home', module search paths # are fairly static expected_paths = [paths[0], stdlib, os.path.join(home, 'DLLs')] + try: + # gh-91985 insert a dll build path + p = os.path.dirname(self.test_exe) + with open(os.path.join(p, 'pybuilddir.txt'), encoding='utf8') as f: + p = os.path.normpath( + os.path.join(p, f'{f.read()}\n$'.splitlines()[0])) + if p != expected_paths[-1]: + expected_paths.insert(-1, p) + del p + except FileNotFoundError: + del p else: version = f'{sys.version_info.major}.{sys.version_info.minor}' stdlib = os.path.join(home, sys.platlibdir, f'python{version}') diff --git a/Modules/getpath.py b/Modules/getpath.py index 9aff19c0af7edd..7b0a35dcbbb580 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -692,6 +692,17 @@ def search_up(prefix, *landmarks, test=isfile): if stdlib_dir: pythonpath.append(stdlib_dir) if platstdlib_dir: + if os_name == 'nt' and real_executable_dir and \ + isfile(joinpath(real_executable_dir, BUILDDIR_TXT)): + try: + p = joinpath( + real_executable_dir, + readlines(joinpath(real_executable_dir, BUILDDIR_TXT))[0], + ) + except IndexError: + p = real_executable_dir + if p != platstdlib_dir: + pythonpath.append(p) # prior to platstdlib_dir pythonpath.append(platstdlib_dir) config['module_search_paths'] = pythonpath