Issue warning when the we can't find a valid standard library during path initialization #145273
Copy link
Copy link
Closed
Closed
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Currently, if we don't find the standard library, we fail with an obscure message.
$ PYTHONHOME=nonsense ./python -c 'print("foo!")'
Fatal Python error: Failed to import encodings module
Python runtime state: core initialized
Exception ignored in the internal traceback machinery:
ModuleNotFoundError: No module named 'traceback'
ModuleNotFoundError: No module named 'encodings'
Stack (most recent call first):This is a common problem, as can be seen with a quick google search. One of the top results is a nonsense AI slop blogpost.
It is generally caused or a misconfigured Python home directory, either by setting PYTHONHOME, or by broken virtual environments.
It would be helpful to show a warning if we are unable to find a valid standard library during initialization.
WARN: Could not find the standard library directory! The Python 'home' directory was set to 'nonsense', is this correct?
Fatal Python error: Failed to import encodings module
Python runtime state: core initialized
Exception ignored in the internal traceback machinery:
ModuleNotFoundError: No module named 'traceback'
ModuleNotFoundError: No module named 'encodings'
Stack (most recent call first):Bad ._pth files can also cause this.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Activity
pythonGH-145273: warn when we can't find the standard library
GH-145273: warn when we can't find the standard library (#145274)
GH-145273: drop build_prefix check from missing stdlib warning (#145437)
pythonGH-145273: skip stdlib warning on module_search_paths_set
GH-145273: skip stdlib warning on module_search_paths_set (#145442)
pythonGH-145273: don't skip missing platstdlib_dir warning if stdlib_…
GH-145273: don't skip missing platstdlib warning if stdlib_zip is fou…
pythonGH-145273: warn when we can't find the standard library (python…
pythonGH-145273: drop build_prefix check from missing stdlib warning (p…
pythonGH-145273: skip stdlib warning on module_search_paths_set (pyth…
pythonGH-145273: don't skip missing platstdlib warning if stdlib_zip …