PermissionError: [Errno 13] Permission denied: '/.cache'

Dockerfile code:

FROM python:3.9-slim
WORKDIR /app

COPY requirements.txt .

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    && rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

ENV PYTHONUNBUFFERED=1 \
    PORT=8000

EXPOSE 8000

RUN echo '#!/bin/bash\n\
uvicorn api:app --host 0.0.0.0 --port 8000 --reload & \
python app.py \n' > /app/run.sh

RUN chmod +x /app/run.sh

CMD ["/app/run.sh"]

Encountered a Permission Error while Building Spaces with Docker. The Sentence Transformer cache file permission is denied

Try set /home/user/huggingface or so to HF_HOME env.

It seems that the directories beginning with a dot in the Hugging Face Spaces become read-only, but Transoformers and other programs try to write to the cache there. I think this is a bug in the broad sense, but I don’t know where to report it…:sob: perhaps @Wauplin ?

I think you can avoid this by changing the cache folder using the method above.

you mean to set os.environ[HF_home]

If you can do that before Transoformers starts, that’s fine too, and you can set the environment variables and Secrets environment variables from the Settings in Spaces.

import os
os.environ["HF_HOME"] = "/home/user/huggingface"

You can also do that directly in your Dockerfile:

ENV PYTHONUNBUFFERED=1 \
    PORT=8000 \
    HF_HOME=/home/user/huggingface