def is_pycaffe_in_dir(dirname=None):
 old_path = sys.path
 if (dirname is not None):
  sys.path = [dirname]
 try:
  imp.find_module('caffe')
 except ImportError:
  return False
 finally:
  sys.path = old_path
 return True

def is_pycaffe_in_dir ( dirname = None ) : old_path = sys . path if ( dirname is not None ) : sys . path = [ dirname ] try : imp . find_module ( 'caffe' ) except ImportError : return False finally : sys . path = old_path return True
returns true if you can "import caffe" from dirname if dirname is none .