From 7936337efcd0df283e6a4697d91a4e88ee4d26a2 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Tue, 18 Aug 2026 14:26:25 +0100 Subject: [PATCH 1/2] gh-155254: Avoid warning about missing stdlib when using _pth files --- Doc/library/sys_path_init.rst | 2 ++ .../2026-08-18-14-19-51.gh-issue-155254.75TMlb.rst | 1 + Modules/getpath.py | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-08-18-14-19-51.gh-issue-155254.75TMlb.rst diff --git a/Doc/library/sys_path_init.rst b/Doc/library/sys_path_init.rst index e6c2cddbe842487..329e49253e91aa4 100644 --- a/Doc/library/sys_path_init.rst +++ b/Doc/library/sys_path_init.rst @@ -105,6 +105,8 @@ Please refer to :mod:`site`'s mechanism, such as :mod:`venv`, that many virtual environment implementations follow. +.. _sys-path-init-_pth-files: + _pth files ---------- diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-18-14-19-51.gh-issue-155254.75TMlb.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-18-14-19-51.gh-issue-155254.75TMlb.rst new file mode 100644 index 000000000000000..4ebe0a417c3f3b8 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-18-14-19-51.gh-issue-155254.75TMlb.rst @@ -0,0 +1 @@ +Avoid warning about missing standard library when using :ref:`sys-path-init-_pth-files`. diff --git a/Modules/getpath.py b/Modules/getpath.py index 6199567bd777aa0..2139e351667bf70 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -769,7 +769,7 @@ def search_up(prefix, *landmarks, test=isfile): # Warn if the standard library is missing, unless pythonpath_was_set was set, as # that skips parts of the stdlib directories calculation — assume the provided # pythonpath is correct. This is how subinterpreters initialize the path for eg. -if not py_setpath and not pythonpath_was_set: +if not py_setpath and not pythonpath_was_set and not pth: home_hint = f"The Python 'home' directory was set to {home!r}, is this correct?" if (not stdlib_zip or not isfile(stdlib_zip)) and (not stdlib_dir or not isdir(stdlib_dir)): hint = home_hint if home else f'sys.prefix is set to {prefix}, is this correct?' From 191e27800ae038f2427c85b05471be83fbdc8a3e Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Tue, 18 Aug 2026 21:34:05 +0100 Subject: [PATCH 2/2] Clarify comment and logic --- Modules/getpath.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/getpath.py b/Modules/getpath.py index 2139e351667bf70..c322d5c4b4c251d 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -766,10 +766,10 @@ def search_up(prefix, *landmarks, test=isfile): # SANITY CHECKS # ****************************************************************************** -# Warn if the standard library is missing, unless pythonpath_was_set was set, as -# that skips parts of the stdlib directories calculation — assume the provided -# pythonpath is correct. This is how subinterpreters initialize the path for eg. -if not py_setpath and not pythonpath_was_set and not pth: +# Warn if we did a search for the standard library and couldn't find it. Never +# show a warning if paths were provided explicitly, since we trust the caller +# knows what they're doing even if the layout doesn't look "normal". +if not (py_setpath or pythonpath_was_set or pth): home_hint = f"The Python 'home' directory was set to {home!r}, is this correct?" if (not stdlib_zip or not isfile(stdlib_zip)) and (not stdlib_dir or not isdir(stdlib_dir)): hint = home_hint if home else f'sys.prefix is set to {prefix}, is this correct?'