def try_import_module(module_name):
 try:
  return import_module(module_name)
 except ImportError as e:
  if (not getattr(e, 'args', None)):
   raise
  desc = e.args[0]
  if (not desc.startswith('No module named ')):
   raise
  desc = desc[len('No module named '):]
  parts = module_name.split('.')
  for i in range(len(parts)):
   if (desc == '.'.join(parts[i:])):
    return None
  raise

def try_import_module ( module_name ) : try : return import_module ( module_name ) except ImportError as e : if ( not getattr ( e , 'args' , None ) ) : raise desc = e . args [ 0 ] if ( not desc . startswith ( 'No module named ' ) ) : raise desc = desc [ len ( 'No module named ' ) : ] parts = module_name . split ( '.' ) for i in range ( len ( parts ) ) : if ( desc == '.' . join ( parts [ i : ] ) ) : return None raise
imports a module .