Open
Description
Feature or enhancement
Proposal:
When import the module, it will raise ModuleNotFoundError if the word is wrong. Like NameError, we can suggest the module name that might be right.
>>>import ant
Traceback (most recent call last):
File <stdin> line 1, in <module>
import ant
^^^
ModuleNotFoundError: no module named 'ant'. Did you mean 'ast'?
To get all of the module, this function can get:
import pkgutil
def get_available_modules():
return [name for _, name, _ in pkgutil.iter_modules()]
available_modules = get_available_modules()
Just need to compare the most likely module name and suggest.
Note: only when the ModuleNotFoundError was raised by python interpreter instead of raise active
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Activity
Locked-chess-official commentedon May 18, 2025
Ok. Maybe some module cannot be imported by the current interpreter. If the Exception raise by this (name is in the "available_modules") maybe we need to suggest another message.
picnixz commentedon May 18, 2025
cc @tomasr8
StanFromIreland commentedon May 18, 2025
It won't be as easy,
importlib
is frozen,pkgutil
is not. IIRC it only had one dependency,sys
.picnixz commentedon May 18, 2025
It's not about being frozen, it's more about the fact that it can be very slow to iterate over millions of installed packages just to find a match as the namespace to look in is the "entire" site-packages in this case.
StanFromIreland commentedon May 18, 2025
That too:-)
Locked-chess-official commentedon May 18, 2025
I think that we can distinguish the grade to compare.
First is the builtin-module.
Second is the standard module.('Lib')
Third is the project module.
Finally is the site-packages.('Lib/site-package')
It can solve some of the speed problem.
Locked-chess-official commentedon May 18, 2025
And we don't need to compare for the pypi packages that wasn't installed.
Locked-chess-official commentedon May 18, 2025
If there is too many site-packages, the solution might be create the virtual environments.
Locked-chess-official commentedon May 18, 2025
And if that's True, the size of the python might be between 1T to 12T, whith means that the computer cannot run any other things, can only be as a docker, I think.
picnixz commentedon May 18, 2025
Actually, we could perhaps use #129329. However, it appears that we're building a global cache anyway, so it may not be impossible after all.
In addition, now that I think about, we should probably only need to present suggestions for top-level packages and leave the rest to attribute suggestion when possible.
3 remaining items