- to get all available modules, run
sys.modules
- to get all installed modules (read: installed by
pip
), you may look atpip.get_installed_distributions()
For the second purpose, example code:
import pipfor package in pip.get_installed_distributions(): name = package.project_name # SQLAlchemy, Django, Flask-OAuthlib key = package.key # sqlalchemy, django, flask-oauthlib module_name = package._get_metadata("top_level.txt") # sqlalchemy, django, flask_oauthlib location = package.location # virtualenv lib directory etc. version = package.version # version number