Get available modules

PythonLibraries

Python Problem Overview


With PHP you have the phpinfo() which lists installed modules and then from there look up what they do.

Is there a way to see what packages/modules are installed to import?

Python Solutions


Solution 1 - Python

Type help() in the interpreter

then

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".                                     

help> modules 

Solution 2 - Python

If you use ipython, which is an improved interactive Python shell (aka "REPL"), you can type import  (note the space at the end) followed by a press of the [TAB] key to get a list of importable modules.

As noted in this SO post, you will have to reset its hash of modules after installing (certain?) new ones. You likely don't need to worry about this yet.

If you don't use ipython, and you haven't tried it, it might be worth checking out. It's a lot better than the basic Python shell, or pretty much any other REPL I've used.

ipython Installation

If you're running linux, there is most likely an ipython package that you can install through your system management tools. Others will want to follow these instructions.

If your installation route requires you to use easy_install, you may want to consider instead using pip. pip is a bit smarter than easy_install and does a better job of keeping track of file locations. This is very helpful if you end up wanting to uninstall ipython.

Listing packages

Note that the above tip only lists modules. For a list which also includes packages —which contain modules— you can do from  + [TAB]. An explanation of the difference between packages and modules can be found in the Modules chapter of the helpful official Python tutorial.

#rtfm

As an added note, if you are very new to python, your time may be better spent browsing the standard library documentation than by just selecting modules based on their name. Python's core documentation is well-written and well-organized. The organizational groups —File and Directory Access, Data Types, etc.— used in the library documentation's table of contents are not readily apparent from the module/package names, and are not really used elsewhere, but serve as a valuable learning aid.

Solution 3 - Python

This was very useful. Here is a script version of this:

# To list all installed packages just execfile THIS file
# execfile('list_all_pkgs.py')
for dist in __import__('pkg_resources').working_set:
   print dist.project_name.replace('Python', '')

Solution 4 - Python

You can list available modules like so:

python -c "for dist in __import__('pkg_resources').working_set:print dist.project_name.replace('Python', '')"

Solution 5 - Python

As aaronasterling says, all .py or .pyc files on sys.path is a module because it can be imported. There are scripts that can let you find what external module is installed in site-packages.

Yolk is a Python command-line tool and library for obtaining information about packages installed by setuptools, easy_install and distutils and it can also query pypi packages.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWizzardView Question on Stackoverflow
Solution 1 - Pythonghostdog74View Answer on Stackoverflow
Solution 2 - PythonintuitedView Answer on Stackoverflow
Solution 3 - PythonRajat SewalView Answer on Stackoverflow
Solution 4 - PythonrannView Answer on Stackoverflow
Solution 5 - PythonpyfuncView Answer on Stackoverflow