> try: > import foo > except ImportError: > logging.error('could not import foo') > sys.exit(1) Why not just let the exception terminate the program? It will have even more information about the problem that caused foo not to load.