Monday, January 7, 2013

How to get a list of installed Python modules programmatically

Code:
import pkgutil

for importer, modname, ispkg in pkgutil.walk_packages(path=None, onerror=lambda x: None):
    print(modname)
Result:

modules
_markerlib
_markerlib.markers
easy_install
pkg_resources
setuptools
setuptools.archive_util
setuptools.command
setuptools.command.alias
setuptools.command.bdist_egg
setuptools.command.bdist_rpm
setuptools.command.bdist_wininst
setuptools.command.build_ext
setuptools.command.build_py
setuptools.command.develop
setuptools.command.easy_install
setuptools.command.egg_info
setuptools.command.install
...

No comments:

Post a Comment