Skip to content

Add notes to ImportError for common issues #127598

Open

Description

@FFY00

Feature or enhancement

Proposal:

ImportErrors are very common, and almost always dependent on the interpreter initialization and/or environment setup. There are many common issues we could try to detect, and give users hints on the possible cause.

  • Failing to load native modules when a module for a different ABI is available
  • Failing to import a non-stdlib module with the site initialization disabled (-S)
  • Failing to import a module available in the user site-packages with the user site initialization disabled (-s)
  • Failing to import a module available in . with PYTHONSAFEPATH/-P enabled
  • Failing to import a module when ignoring PYTHON* environment variables (-E) but PYTHONPATH or PYTHONHOME are set (which users might be relying on)
  • (suggest more!)

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. ZeroIntensity commented on Dec 4, 2024

    @ZeroIntensity
    Member

    Failing to import a module when ignore PYTHON* environment variables (-E) but PYTHONPATH or PYTHONHOME are set (which users might be relying on)

    Related: #125873

  2. MonadChains commented on Jul 19, 2025

    @MonadChains
    Contributor

    Hi @FFY00 and @ZeroIntensity I open a mr to add some flavour text for this case:

    Failing to import a non-stdlib module with the site initialization disabled (-S)

  3. added a commit that references this issue on Jul 20, 2025
  4. MonadChains commented on Jul 24, 2025

    @MonadChains
    Contributor

    I was also thinking to add the message for the cases where:

    Failing to import a module available in the user site-packages with the user site initialization disabled (-s)
    Failing to import a module available in . with PYTHONSAFEPATH/-P enabled

    however, I'm not sure how to handle such cases, since these are options think mainly for safety reasons, is it safe to traverse the removed path on the traceback when such the ImportError happens?

  5. added a commit that references this issue on Aug 4, 2025
  6. added a commit that references this issue on Aug 19, 2025
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions