views:

71

answers:

2

I have recently started learning Python and I have 2 questions relating to modules.

  1. Is there a way to obtain a list of Python modules available (i.e. installed) on a mchine?
  2. I am using Ubuntu Karmic and Synaptic for package management. I have just installed a python module.Where is the module code actually stored on my machine? (is there a default [recommended] location that modules are stored)?
+5  A: 

1) Is there a way to obtain a list of Python modules available (i.e. installed) on a mchine?

This works for me:

help('modules')

.

2) Where is the module code actually stored on my machine?

Usually in /lib/site-packages in your Python folder. (At least, on Windows.)

You can use sys.path to find out what directories are searched for modules.

Xavier Ho
If you want the location of a specific module, `import` it and look at it's `__file__` attribute. Works for most of them.
Noufal Ibrahim
+1 for `help('modules')`. Didn't know that. :)
Noufal Ibrahim
+1  A: 
  1. You can iterate through directories listed in sys.path to find all modules (except builtin ones).
  2. It'll probably be somewhere around /usr/lib/pythonX.X/site-packages (again, see sys.path). And consider using native Python package management (via pip or easy_install, plus yolk) instead, packages in Linux distros-maintained repositories tend to be outdated.
PiotrLegnica