Skip to content

Remove idlelib from sys.path in IDLE run process #134300

Closed

Description

@Locked-chess-official

When use IDLE to open a file and start a new IDLE windows from "Python Shell" button, you can import the modules that are the child modules in the module "idlelib", such as "help", "pyshell". Think for that there are many schools still use IDLE to teach python to prevent the students to install malicious plugins from other IDE, if the students try to import these modules, it will result in misleading.

import help

This code is wrong in cmd and any other IDE but "normal" in IDLE, and what is imported is "idlelib.help".

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on May 20, 2025
  2. gaogaotiantian commented on May 20, 2025

    @gaogaotiantian
    Member

    Hi, there's a quick suggestion - the title of the issue should be more descriptive about the topic, rather than a very generic question, so the triagers and core devs can understand what's the issue about (whether it's in their area of expertise) without clicking into it.

  3. picnixz commented on May 20, 2025

    @picnixz
    Member

    cc @terryjreedy I don't understand the issue but since it seems to be IDLE related, I'm pinging you to have a look and decide the scope.

  4. ronaldoussoren commented on May 20, 2025

    @ronaldoussoren
    Contributor

    Which version of Python are you using? And what OS are you on?

    On macOS I get:

    Python 3.12.10 (v3.12.10:0cc81280367, Apr  8 2025, 08:46:59) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
    Enter "help" below or click "Help" above for more information.
    import help
    Traceback (most recent call last):
      File "<pyshell#0>", line 1, in <module>
        import help
    ModuleNotFoundError: No module named 'help'
    
  5. terryjreedy commented on May 20, 2025

    @terryjreedy
    Member

    This is a subissue of #69674; I am leaving this open to patch this specific issue, which is that .../idlelib is sometimes on sys.path in the separate user process where user code is normally executed. ('Normally', means when option -n is not added to IDLE startup.) I noted in 2015 that this depends on how IDLE is started; and added today that it may have changed with version. It also depends the system. With 3.14 on my Win 10, >>> import help works. On my macbook with Catalina, it raises as Ronald shows above. (Note to anyone else: the splash line Enter "help" below ... is IDLE Shell specific.) Checking sys.path (most easily with for p in sys.path: print(p) shows that .../idlelib is present on Windows but not on Mac.

    @Locked-chess-official What OS, python version, and IDLE startup method did you use.

    I think adding the following to idlelib.run near the top should work.

    for i in (0, 1):
       if sys.path[i].endswith('idlelib'):
        del sys.path[i]
        break
    
  6. changed the title [-]Is it needs to be fixed or writed in docs for warning?[/-] [+]Remove idlelib from sys.path in IDLE run process[/+] on May 20, 2025
  7. Locked-chess-official commented on May 21, 2025

    @Locked-chess-official
    ContributorAuthor

    What OS, python version, and IDLE startup method did you use.

    Windows, 3.12 and 3.13

  8. Locked-chess-official commented on May 21, 2025

    @Locked-chess-official
    ContributorAuthor

    Windows, 3.12 and 3.13  Windows, 3.12 和 3.13
    When use idle.bat to start, it sames too.

  9. terryjreedy commented on Dec 12, 2025

    @terryjreedy
    Member

    Since idlelib is only sometimes present, and idlelib.run runs when it is absent, it must not depend on it being present. Therefore safe to remove. User code depending on its presence is buggy in not running without IDLE. User code failing because of its presence has a legitimate complaint.

  10. removed
    stdlibStandard Library Python modules in the Lib/ directory
    on Jan 15, 2026
  11. added 4 commits that reference this issue on Jul 1, 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

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions