Re: [Tutor] List installed python modules

2008-07-21 Thread Tim Golden

Eli Brosh wrote:

Hello,

Is there a way to get a list of installed python modules and their 
versions ?
i.e. I would like to know if matplotlib is installed on my computer and 
what version is it.

And so with other modules.


You've got two slightly different requirements there:

1) List all modules installed

and

2) Is *this* module installed?

The second is easy:


try:
import ModuleX
except ImportError:
print "ModuleX is not installed"
else:
print "ModuleX is installed"
print "with version", getattr (ModuleX, __VERSION__, "unknown")



There's no prescribed attribute for version, so you
might have to check a few like that if you didn't
know what to look for.

The first is harder, and in effect impossible in general.
Given a well-known and controlled setup, you could do
various things like interrogate the system's package
database or scan sys.path looking for modules & packages,
but it's all a bit hazy and wouldn't take into account,
say, a library module local to a particular application
which differs from a centrally-installed one for version
reasons.

TJG

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] List installed python modules

2008-07-21 Thread Eli Brosh
Hello,

Is there a way to get a list of installed python modules and their versions ?
i.e. I would like to know if matplotlib is installed on my computer and what 
version is it.
And so with other modules.

Thanks
Eli
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor