Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: A complete list of modules [duplicate]

Tags:

python

module

How do I get a list of all python modules available?

I don't want modules of modules. Just a basic list of all modules available in sys.path.

help('modules') is not the solution, because I want it available as a variable and it imports those modules, which has side effects.

Edit: With side effects I mean libraries like kivy of http://kivy.org/, which make use of the fact, that code is executed once you import it.

like image 740
Dave Halter Avatar asked Mar 30 '12 17:03

Dave Halter


1 Answers

pkgutil - Utilities to support packages

this will yield a tuple for all submodules on sys.path:

pkgutil.iter_modules()

to see what's loaded, look at:

sys.modules

"This is a dictionary that maps module names to modules which have already been loaded"

  • http://docs.python.org/library/sys.html#sys.modules

a list of loaded modules:

sys.modules.keys() 
like image 145
Corey Goldberg Avatar answered Oct 01 '22 11:10

Corey Goldberg