How to list python Modules/Packages?

Python comes with many standard library modules like OS, Json,urllib, zipfile and re. There are vast number of third party modules also. PyPI, The Python Package Index maintains the list of Python packages available. You can install these modules using Python pip  or any other OS specific package managers.

There are multiple ways to list  modules/packages installed in Python.

1. List Python modules/packages using pip

We can use any of the following commands

1 2 3   pip freeze  

OR

1 2 3   pip list  

Sample output is below

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15   [root@test.test.com ~]# pip list ansible (2.2.0.0) argparse (1.4.0) Babel (0.9.4) backports.sslmatchhostname (3.5.0.1) cachedproperty (1.3.0) cassandrapylib (0.0.0) Conch (8.2.0) distribute (0.7.3) djangotagging (0.3.1) dockercompose (1.9.0) dockerpy (1.10.6) dockerpycreds (0.2.1)  

2. List Python modules Using Python’s “help” function

You can use help function in python to get the list of modules installed. First you need to get into python console and then run the following command

1 2 3   help(“modules”)  

Please check sample output below

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18   [root@test.test.com ~]# python Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) [GCC 4.4.7 20120313 (Red Hat 4.4.717)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> help(“modules”) Please wait a moment while I gather a list of all available modules... BaseHTTPServer _vendor htmllib sched Bastion _warnings httplib select CDROM _weakref httplib2 selinux CGIHTTPServer _xmlplus idlelib semanage Canvas _yaml ihooks seobject ConfigParser abc imageop sepolgen Cookie aifc imaplib setools Crypto ansible imghdr sets DLFCN anydbm imp setuptools DbgPlugInDiggers argparse imputil sgmllib  

3 . List Python modules using pydoc

Pydoc is the Python documentation tool. This can be used to list the availble modules like following

1 2 3 4 5 6 7 8 9 10 11 12 13 14   pydoc modules Please wait a moment while I gather a list of all available modules... BaseHTTPServer _vendor htmllib sched Bastion _warnings httplib select CDROM _weakref httplib2 selinux CGIHTTPServer _xmlplus idlelib semanage Canvas _yaml ihooks seobject ConfigParser abc imageop sepolgen Cookie aifc imaplib setools Crypto ansible imghdr sets DLFCN anydbm imp setuptools DbgPlugInDiggers argparse imputil sgmllib  

Author: , 0000-00-00