Reputation: 1674
Is there a possible way to get a list of all possible python modules on the system. For example in IDLE you can do something like help('modules')
and obtain a sorted list of installed packages. But what I would like is to programmatically gather a list from inside of a python program. Something like:
possible_packages = ["os","pty","psutil",..]
And from there be able to parse through that list. How can I do this within a python program?
Upvotes: 1
Views: 53
Reputation: 107040
You can use pkgutil.walk_packages
:
from pkgutil import walk_packages
possible_packages = [module for _, module, _ in walk_packages()]
Upvotes: 1