Checking for module availability programmatically in Python?

Posted by user248237 on Stack Overflow See other posts from Stack Overflow or by user248237
Published on 2010-04-11T16:20:47Z Indexed on 2010/04/11 16:23 UTC
Read the original article Hit count: 368

Filed under:
|
|

given a list of module names (e.g. mymods = ['numpy', 'scipy', ...]) how can I check if the modules are available?

I tried the following but it's incorrect:

for module_name in mymods:
  try:
    import module_name
  except ImportError:
    print "Module %s not found." %(module_name)

thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about python-module