Reputation: 72975
I'm just starting out with Python, and have found out that I can import various libraries. How do I find out what libraries exist on my Mac that I can import? How do I find out what functions they include?
I seem to remember using some web server type thing to browse through local help files, but I may have imagined that!
Upvotes: 13
Views: 36960
Reputation: 1250
Considering that in every operating system most of python's packages are installed using 'pip' (see pip documentation) you can also use the command 'pip freeze' on a terminal to print a list of all the packages you have installed through it. Other tools like 'homebrew' for macOS (used when for some reason you can't install a package using pip) have similar commands, in this specific case 'brew list'.
Upvotes: 2
Reputation: 34685
For the web server, you can run the pydoc
module that is included in the python distribution as a script:
python /path/to/pydoc.py -p 1234
where 1234
is the port you want the server to run at. You can then visit http://localhost:1234/
and browse the documentation.
Upvotes: 7
Reputation: 2660
just run the Python interpeter and type the command import "lib_name" if it gives an error, you don't have the lib installed...else you are good to go
Upvotes: 3
Reputation: 1660
You can install another library: yolk.
yolk is a python package manager and will show you everything you have added via pypi. But it will also show you site-packages added through whatever local package manager you run.
Upvotes: 3
Reputation: 8210
On Leopard, depending on the python package you're using and the version number, the modules can be found in /Library/Python:
/Library/Python/2.5/site-packages
or in /Library/Frameworks
/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages
(it could also be 3.0 or whatever version)... I guess it is quite the same with Tiger
Upvotes: 2
Reputation: 28278
Every standard python distribution has these libraries, which cover most of what you will need in a project.
In case you need to find out if a library exists at runtime, you do it like this
try:
import ObscureModule
except ImportError:
print "you need to install ObscureModule"
sys.exit(1) # or something like that
Upvotes: 3
Reputation: 258348
From the Python REPL (the command-line interpreter / Read-Eval-Print-Loop), type help("modules")
to see a list of all your available libs.
Then to see functions within a module, do help("posix")
, for example. If you haven't import
ed the library yet, you have to put quotes around the library's name.
Upvotes: 40