Python: List Modules, List Loaded Modules

By Xah Lee. Date: . Last updated: .

List Available Modules

To list all available modules in module path, type

(on Microsoft Windows, pydoc is at C:/Python39/Tools/scripts/pydoc3.py. you might need to type the full path, or add it to your Microsoft Windows PATH environment variable. [see Windows Environment Variable Tutorial] )

or in python code:

# python 3

# prints a list of existing modules
print(help("modules"))

List Loaded Modules

Loaded module names is stored in the variable sys.modules.

import sys
import pprint

# pretty print loaded modules
pprint.pprint(sys.modules)

# sample output

# {'__main__': <module '__main__' from 'c:\\Users\\xah\\.emacs.d\\temp\\x20221010_0935_b29.py3'>,
#  '_abc': <module '_abc' (built-in)>,
#  '_codecs': <module '_codecs' (built-in)>,
# ...
#  'builtins': <module 'builtins' (built-in)>,
# ...
#  'zipimport': <module 'zipimport' (frozen)>}

Python: Paths and Module