def __init__(self, version=None):
        """
        Initialize a new Postgres object
        :param version: version to use. If it is not set, use the latest version in .pyembedpg directory. If not present
                        use the latest version remotely. Use 'local' to use the local postgres version installed on the machine
        :return:
        """
        home_dir = expanduser("~")
        self._cache_dir = os.path.join(home_dir, PyEmbedPg.CACHE_DIRECTORY)

        # if version is not specified, check local last version otherwise get last remote version
        self.version = version
        if not self.version:
            self.version = self.get_latest_local_version()
            if not self.version:
                self.version = self.get_latest_remote_version()

        if version == PyEmbedPg.LOCAL_VERSION:
            full_path = spawn.find_executable('postgres')
            if not full_path:
                raise PyEmbedPgException('Cannot find postgres executable. Make sure it is in your path')
            self._version_path = os.path.dirname(full_path)
        else:
            self._version_path = os.path.join(self._cache_dir, self.version)