13aal
13aal

Reputation: 1674

Obtaining a list of all possible python modules on the system

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

Answers (1)

blhsing
blhsing

Reputation: 107040

You can use pkgutil.walk_packages:

from pkgutil import walk_packages
possible_packages = [module for _, module, _ in walk_packages()]

Upvotes: 1

Related Questions