Python: List Modules, List Loaded Modules
List available modules
# prints a list of existing modules print(help("modules")) # Please wait a moment while I gather a list of all available modules... # 20260819_1605_b020 _ssl faulthandler queue # 30fcd23745efe32ce681__mypyc _stat fd7dcdb10166ebd4db98__mypyc quopri # PIL _statistics filecmp random # __future__ _string fileinput re # __hello__ _strptime fnmatch reprlib # ... # _sre errno pytokens
List installed modules
# python prints a list of installed modules from importlib.metadata import distributions for dist in distributions(): print(f"{dist.metadata['Name']}=={dist.version}") # black==26.5.1 # cffi==2.1.0 # click==8.4.2 # cmarkgfm==2025.10.22 # colorama==0.4.6 # Markdown==3.10.2 # mypy_extensions==1.1.0 # packaging==26.2 # pathspec==1.1.1 # pillow==12.3.0 # pip==26.2 # platformdirs==4.11.0 # pycparser==3.0 # pytokens==0.4.1
List loaded modules
Loaded module names is stored in the variable sys.modules.
# print list of Loaded modules import sys import pprint # pretty print loaded modules pprint.pprint(sys.modules) # {'__main__': <module '__main__' from 'c:\\Users\\xah\\.emacs.d\\temp\\20260819_1608_22cd.py'>, # '_abc': <module '_abc' (built-in)>, # '_ast': <module '_ast' (built-in)>, # ... # 'zipimport': <module 'zipimport' (frozen)>}