def setup(self, path=None):
        """
        Look for SExtractor program ('sextractor', or 'sex').
        If a full path is provided, only this path is checked.
        Raise a SExtractorException if it failed.
        Return program and version if it succeed.
        """

        # -- Finding sextractor program and its version
        # first look for 'sextractor', then 'sex'

        candidates = ['sextractor', 'sex']

        if (path):
            candidates = [path]

        selected = None
        for candidate in candidates:
            try:
                p = subprocess.Popen(candidate, shell=True,
                                     stdin=subprocess.PIPE,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     close_fds=True)
                (_out_err, _in) = (p.stdout, p.stdin)
                versionline = _out_err.read()
                if (versionline.find("SExtractor") != -1):
                    selected = candidate
                    break
            except IOError:
                continue

        if not(selected):
            raise SExtractorException(
                """
                  Cannot find SExtractor program. Check your PATH,
                  or provide the SExtractor program path in the constructor.
                  """
            )

        _program = selected

        # print versionline
        _version_match = re.search("[Vv]ersion ([0-9\.])+", versionline)
        if not _version_match:
            raise SExtractorException(
                "Cannot determine SExtractor version."
            )

        _version = _version_match.group()[8:]
        if not _version:
            raise SExtractorException(
                "Cannot determine SExtractor version."
            )

        # print "Use " + self.program + " [" + self.version + "]"

        return _program, _version