No matter what, I can't duplicate any space :(

I have some spaces duplicated, but I’ve been having a Build Error, lately. It doesn’t mean which space I’m trying to duplicate, I always get it.

Trying to duplucate “Face Swapper”, I get “

→ ERROR: process “/bin/sh -c pip install --no-cache-dir -r /tmp/requirements.txt” did not complete successfully: exit code: 2”

Trying to duplicate “Face Swap”, i get:

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed to build ‘pillow’ when getting requirements to build wheel

→ ERROR: process “/bin/sh -c pip install --no-cache-dir -r /tmp/requirements.txt” did not complete successfully: exit code: 1

Trying to dupicate “Face Swap Pro”, i get:

pip._vendor.pyproject_hooks._impl.BackendUnavailable: Cannot import 'setuptools.build_meta'

--> ERROR: process "/bin/sh -c pip install --no-cache-dir -r /tmp/requirements.txt" did not complete successfully: exit code: 2

I don’t know. I only click “Duplicate” and don’t do anything more… And all spaces are working fine before trying to duplicate.

I’m really new to this, so, I’m not sure what’s wrong nor what to do…

Thanks!

1 Like

Duplicating an HF Space and having it work flawlessly as-is is a rare case.

  1. Libraries are frequently updated

  2. Hugging Face Spaces runtime configurations change every few months

If these changes happen to not cause issues, the duplicated Space will work as-is.

Looking at the logs, the cause this time was likely mainly a configuration change on the HF side. Simply adding the line python_version: “3.10” to README.md might make it work…


What “duplicating a Space” actually does (why it can fail)

A Space is a git repository. When you duplicate it, you create a new repo and trigger a fresh rebuild: dependencies are re-resolved and reinstalled, and the app restarts on the current Spaces base environment. Any mismatch between the code’s assumptions and today’s runtime can surface at this point. (Hugging Face)


Most common causes (that match errors like Failed to build pillow and Cannot import setuptools.build_meta)

1) Python version drift → incompatible packages

If the build ends up using a newer Python than the Space’s dependencies support, pip may fail (or try to compile from source and fail).

  • Example: Pillow only officially supports Python 3.13 starting from Pillow 11.0.0. If the duplicated Space uses Python 3.13 but requirements pin an older Pillow, it can break. (Pillow (PIL Fork))

Typical symptoms

  • Failed to build 'pillow'
  • lots of compiler output or “building wheel” steps

Fix

  • Pin the Space’s Python version (see “Fix checklist” below), or
  • Upgrade pins (e.g., Pillow to a version compatible with your Python).

2) Broken/old build tooling → setuptools.build_meta import failures

BackendUnavailable: Cannot import 'setuptools.build_meta' is a packaging toolchain problem: the build backend can’t load because pip/setuptools/wheel is missing or incompatible.

This error shows up widely in real projects and is commonly fixed by upgrading build tooling. (Stack Overflow)

Fix

  • Use a pre-requirements.txt to upgrade pip, setuptools, wheel before installing your main requirements.txt. Spaces supports this explicitly. (Hugging Face)

3) Missing system (apt) libraries for compiled dependencies

Some Python packages need OS libraries (and headers) to build. If pip can’t find a prebuilt wheel, it falls back to compiling, which then fails without the right OS deps.

Spaces supports installing Debian packages via packages.txt (apt). (Hugging Face)

Typical symptoms

  • errors mentioning jpeg, zlib, freetype, png, gcc, cmake, etc.

Fix

  • Add packages.txt with required apt packages (examples below).

4) Secrets/tokens not present in the duplicate

If the Space needs access tokens (private models, gated repos, external APIs), the duplicate often fails at runtime (or while downloading assets) because secrets are not automatically copied to duplicates. Variables can be auto-populated; secrets generally are not. (Hugging Face)

Fix

  • Add the required secrets in the duplicate Space settings (or via API). (Hugging Face)

5) Platform-side cloning/build incidents

Sometimes every build/duplicate fails due to a transient backend issue (“error while cloning repository”, build queue stuck, etc.). HF community threads document cases where even trivial Spaces fail with cloning errors. (Hugging Face Forums)

Fix

  • Confirm by duplicating a trivial “hello world” Space. If that also fails, treat it as platform-side and use workarounds (e.g., reduce repo size, avoid bundling large data in the Space repo, move large assets to a dataset/model repo). (Hugging Face Forums)

Fix checklist (beginner-safe, minimal changes)

A) Lock the Python version used by the build

In README.md, add a YAML header (or edit existing) to force a stable Python (3.10 or 3.11 are common choices):

---
sdk: gradio
python_version: "3.11"
---

Spaces supports python_version and documents its default as 3.10. (Hugging Face)


B) Upgrade build tooling before installing requirements

Create pre-requirements.txt:

pip
setuptools
wheel

Spaces installs this before requirements.txt. (Hugging Face)


C) Make Pillow installable without compiling

Pick one approach:

  • If staying on Python 3.13: ensure Pillow is modern enough (Pillow 11+ supports 3.13). (Pillow (PIL Fork))
    Example in requirements.txt:

    Pillow>=11
    
  • If staying on Python 3.10/3.11: unpin Pillow or use a known-good range (often avoids source builds).


D) If any package still compiles, add apt deps via packages.txt

Create packages.txt (one per line). For Pillow-related builds, common ones are:

build-essential
libjpeg-dev
zlib1g-dev
libpng-dev
libfreetype6-dev

Spaces explicitly supports packages.txt installed by apt-get. (Hugging Face)


E) Re-add required secrets/tokens in the duplicate

If the app downloads private/gated resources, set HF_TOKEN (or other keys) as a Space secret in the duplicate. Secrets are exposed as environment variables at runtime. (Hugging Face)


Quick “symptom → cause → fix” map

What you see in logs Likely cause Most effective fix
Cannot import 'setuptools.build_meta' build tooling issue add pre-requirements.txt with pip/setuptools/wheel (Hugging Face)
Failed to build pillow on newer Python Python/package mismatch pin python_version, or bump Pillow (3.13 needs Pillow 11+) (Hugging Face)
compilation errors mentioning jpeg/zlib/freetype missing OS libs add packages.txt apt deps (Hugging Face)
runtime KeyError: API_TOKEN / auth failures missing secrets add secrets in duplicate Space settings (Hugging Face)
Error while cloning repository across many Spaces platform-side incident or repo-size issue test with trivial Space; move large assets out of Space repo (Hugging Face Forums)
1 Like

You are not doing anything wrong.

Duplicating a Space triggers a full rebuild.
The rebuild fails because some dependencies like pillow need system libraries.
The original Spaces work because they were built earlier or use cached environments.

2 Likes

Thank you for the explanation and tips! I’m going to try these solutions :slight_smile:

1 Like

Thank you for the info!

1 Like