Hi there,
With PHP you have the phpinfo() which lists installed modules and then from there look up what they do.
As a python newbie, is there a way to see what items are installed to import?
Hi there,
With PHP you have the phpinfo() which lists installed modules and then from there look up what they do.
As a python newbie, is there a way to see what items are installed to import?
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 (some?) 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. If you're running windows, and maybe OS/X, you may have to download and install it yourself. If you're running linux, there is likely —certainly on Debian-like systems, such as Ubuntu— an ipython
package that you can install through your system management tools.
Another option may be to install through Python itself. Python's most common means of package installation, easy_install
, unfortunately does not keep track of where it puts things, making a complex package like ipython
not so easy to uninstall, should that prove necessary. pip
is a more advanced package manager which does keep track of these things in at least a somewhat thorough manner.
Note that the above tip only lists modules. For a list which also includes packages —which contain modules— you can do from
+ [TAB]
. More on the difference between packages and modules can be read in that chapter of the helpful official Python tutorial.
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 documentation is generally 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.
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
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.
You can list available modules like so:
python -c "for dist in __import__('pkg_resources').working_set:print dist.project_name.replace('Python', '')"