Skip to content

Allow omitting _pyrepl module #145035

Description

@zooba

Currently, launching Python without the _pyrepl module present causes it to abort. It would be better if it simply went into regular repl mode, rather than requiring the user to set an env var, as this would allow distributors to simply omit the module rather than having to patch and rebuild CPython.

cpython/Modules/main.c

Lines 281 to 286 in 175ab31

PyObject *pyrepl = PyImport_ImportModule("_pyrepl.main");
if (pyrepl == NULL) {
fprintf(stderr, "Could not import _pyrepl.main\n");
res = pymain_exit_err_print();
goto done;
}

I would prefer messages about ModuleNotFoundError here to only be shown in verbose mode, though other errors could still cause a full failure (if that's what the maintainers think is best... I disagree, but it's not important to me like ModuleNotFoundError would be).

Linked PRs

Activity

  1. added
    topic-replRelated to the interactive shell
    3.15pre-release feature fixes, bugs and security fixes
    on Feb 20, 2026
  2. self-assigned this
    on Feb 23, 2026
  3. zooba commented on Feb 23, 2026

    @zooba
    MemberAuthor

    Given how pydoc was refactored, and that I don't want to un-refactor it, it appears that omitting _pyrepl will also break pydoc. I expect that to not be an issue for anyone who's interested in restricting REPL usage (e.g. in production code), so will just leave it documented. Turns out to not be an issue, though pydoc does regress to its most basic form without _pyrepl (which I still think is okay).

  4. added a commit that references this issue on Feb 23, 2026
  5. added a commit that references this issue on Mar 9, 2026
  6. added a commit that references this issue on Mar 10, 2026
  7. StanFromIreland commented on Mar 15, 2026

    @StanFromIreland
    Member

    Triage: Can this be closed now?

  8. added a commit that references 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

Labels

3.15pre-release feature fixes, bugs and security fixesextension-modulesC modules in the Modules dirpendingThe issue will be closed if no feedback is providedtopic-replRelated to the interactive shelltype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions