Skip to content

Issue warning when the we can't find a valid standard library during path initialization #145273

Description

@FFY00

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

Activity

  1. added
    type-featureA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Feb 26, 2026
  2. added 7 commits that reference this issue on Feb 26, 2026
  3. added 4 commits that reference this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions