deepfakes/faceswap · error · FaceswapError

The output location must be a string not a {type(self.locati

Error message

The output location must be a string not a {type(self.location)}

What it means

ImagesSaver overrides _check_location_exists and requires the output location to be a string (a single folder path). Passing a list/tuple of destinations, None, or a Path-like object raises this FaceswapError before the superclass existence check runs.

Source

Thrown at lib/image.py:1300

    >>>     saver.save(filename, image)
    >>> saver.close()
    """

    def __init__(self, path, queue_size=8, as_bytes=False):
        logger.debug(parse_class_init(locals()))
        super().__init__(path, queue_size=queue_size)
        self._as_bytes = as_bytes

    def _check_location_exists(self):
        """ Check whether the output location exists and is a folder

        Raises
        ------
        FaceswapError
            If the given location does not exist or the location is not a folder
        """
        if not isinstance(self.location, str):
            raise FaceswapError("The output location must be a string not a "
                                f"{type(self.location)}")
        super()._check_location_exists()
        if not os.path.isdir(self.location):
            raise FaceswapError(f"The output location '{self.location}' is not a folder")

    def _process(self, queue):
        """ Saves images from the save queue to the given :attr:`location` inside a thread.

        Parameters
        ----------
        queue: queue.Queue()
            The ImageIO Queue
        """
        executor = futures.ThreadPoolExecutor(thread_name_prefix=self.__class__.__name__)
        assert self._error_state is not None
        while True:
            if self._error_state.has_error:
                logger.debug("[%s] Thread error detected in worker thread", self._name)

View on GitHub (pinned to f530cb7508)

Solutions

  1. Pass a single string folder path to ImagesSaver.
  2. Default unset config values to a concrete string output folder.
  3. Wrap Path objects with str(...) if using pathlib.

Example fix

# before
 saver = ImagesSaver(['/out/a', '/out/b'])  # FaceswapError

# after
saver = ImagesSaver('/out/a')  # one output folder only
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(output_location, str) or not output_location:
    raise SystemExit('output location must be a non-empty string folder path')

Type guard

def is_valid_output_location(loc) -> bool:
    return isinstance(loc, str) and len(loc) > 0

Try / catch

try:
    saver = ImagesSaver(loc)
except FaceswapError as err:
    if 'must be a string' in str(err):
        loc = str(loc[0]) if isinstance(loc, (list, tuple)) else str(loc)
        saver = ImagesSaver(loc)
    else:
        raise

Prevention

When it happens

Trigger: Constructing ImagesSaver with a list of output folders (only one folder is supported), with None because a config variable was unset, or with pathlib.Path on versions expecting str.

Common situations: Reusing an input list for the output argument; config parsing that yields None; scripts building output paths programmatically and passing a non-string.

Related errors


AI-assisted analysis of deepfakes/faceswap@f530cb7508 (2026-08-15). Data as JSON: /api/errors/a08160cea6edb9a5. Report an issue: GitHub.