Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Locked-chess-official opened this issue May 20, 2025 · 6 comments
Open

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

Locked-chess-official opened this issue May 20, 2025 · 6 comments
Labels
stdlib Python modules in the Lib dir topic-IDLE

Comments

@Locked-chess-official
Copy link

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".

@picnixz picnixz added stdlib Python modules in the Lib dir topic-IDLE labels May 20, 2025
@gaogaotiantian
Copy link
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.

@picnixz
Copy link
Member

picnixz commented May 20, 2025

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.

@ronaldoussoren
Copy link
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'

@terryjreedy
Copy link
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

@terryjreedy terryjreedy changed the title Is it needs to be fixed or writed in docs for warning? Remove idlelib from sys.path in IDLE run process May 20, 2025
@Locked-chess-official
Copy link
Author

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

Windows, 3.12 and 3.13

@Locked-chess-official
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-IDLE
Projects
None yet
Development

No branches or pull requests

5 participants