4

How can I print the libraries that Python already has. Such as os, math, socket etc.

Is there a process similar to "pip list" || "pip freeze" which prints the libraries I install?

(I am new to Python, if I have a terrible misconception about python libraries please help me out).

Ébe Isaac
  • 11,563
  • 17
  • 64
  • 97
costadvl
  • 128
  • 2
  • 12
  • Possible duplicate of [How can I get a list of locally installed Python modules?](http://stackoverflow.com/questions/739993/how-can-i-get-a-list-of-locally-installed-python-modules) – GAVD Nov 15 '16 at 05:00
  • @GAVD At first I thought the same thing. But I think OP Is actually looking for all modules in the standard library. – idjaw Nov 15 '16 at 05:02
  • Why is the documentation not enough in this case? – idjaw Nov 15 '16 at 05:02
  • 1
    He can see [this](https://docs.python.org/3/py-modindex.html) :) – GAVD Nov 15 '16 at 05:11
  • @idjaw just want to know if that can be done – costadvl Nov 15 '16 at 05:13

1 Answers1

4

You can do this by printing out help('modules'):

Only showing a few lines of the output since it is big

>>> help('modules')

Please wait a moment while I gather a list of all available modules...

IN                  aifc                hmac                sf
__future__          another             html                shelve
_ast                antigravity         http                shlex
_bisect             argparse            idlelib             shutil
_bootlocale         array               imaplib             signal
_bz2                ast                 imghdr              site
_codecs             asynchat            imp                 smtpd
_codecs_cn          asyncio             importlib           smtplib
_codecs_hk          asyncore            inspect             sndhdr
_codecs_iso2022     atexit              io                  socket
_codecs_jp          audioop             ipaddress           socketserver
_codecs_kr          base64              itertools           something
_codecs_tw          bdb                 json                sqlite3
_collections        binascii            keyword             sre_compile
_collections_abc    binhex              lib2to3             sre_constants
_compat_pickle      bisect              linecache           sre_parse
_compression        builtins            locale              ssl
_crypt              bz2                 logging             stat
_csv                cProfile            lzma                statistics
_ctypes             calendar            macpath             string

You could also narrow down by searching for matching words. For example, you want to lookup something that might match "collections":

>>> help('modules collections')

Here is a list of modules whose name or summary contains 'collections'.
If there are any, enter a module name to get more help.

_collections - High performance data structures.
_collections_abc - Abstract Base Classes (ABCs) for collections, according to PEP 3119.
collections
collections.__main__
collections.abc
test.test_collections - Unit tests for collections.py.
test.test_defaultdict - Unit tests for collections.defaultdict.
pip._vendor.requests.packages.urllib3._collections

Then, if you want help on a particular module, to get more information on it, you just call the help on that particular one:

>>> help('collections')
idjaw
  • 25,487
  • 7
  • 64
  • 83