Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

sys.path[0] Is Set Differently From the Rest of sys.path #109853

Copy link
Copy link
@ericsnowcurrently

Description

@ericsnowcurrently
Issue body actions

Feature or enhancement

Currently sys.path[0] is set by pymain_run_python() (in Modules/main.c). This happens after pymain_init(), which initializes the runtime, including the rest of sys.path (via getpath.py and site.py). This makes it harder to reason about and introduces extra complexity for subinterpreters. (See gh-109793 and gh-109794.)

We should consider calculating sys.path[0] and setting it to its own PyConfig field via getpath.py, when the rest of the base sys.path is calculated. We may need a later check to verify that there is a matching importer, as pymain_run_python() does. (FWIW, it isn't clear that there's any value to storing the sys.path[0] value on the global _PyPathConfig.)

Also, we currently wait to actually set sys.path[0] (for the main interpreter) until after the readline/rlcompleter modules are imported in pymain_run_python(). We'd need to factor that in.

CC @zooba, @vstinner, @ncoghlan

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status
    Todo
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.