Skip to content

Improve the error when failing to setup sys.path for initialization #127600

Closed as not planned
@FFY00

Description

@FFY00

Feature or enhancement

Proposal:

Currently, it fails like this, which isn't very helpful:

$ PYTHONHOME=inexistent ./python
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'

Current thread 0x000076eaa9477740 (most recent call first):
  <no Python frame>

After getpath is done, we could try to detect a bad sys.path list and provide a better error.

This is something that I have personally hit several times (though I might not represent the regular user 😅), and the first time it took me a little bit to figure out that this means that we messed up the sys.path calculation. I have seen a couple users also run into this in CI environments, where it is very difficult to debug and try to reproduce, so unless you know that spotting "Failed to import encodings module" usually means sys.path got somehow messed up, it's very difficult to deal with it.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions