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

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpermissionerror-errno-13-permission-denied-cache%2F146951%3E%5C
**Category:** Spaces\
**Created:** [March 22, 2025, 4:01pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpermissionerror-errno-13-permission-denied-cache%2F146951 "2025-03-22T16:01:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Senzen](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/senzen/32/35934_2.png) [@Senzen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FSenzen)%5C
**Post date:** [March 22, 2025, 4:01pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpermissionerror-errno-13-permission-denied-cache%2F146951%2F1 "2025-03-22T16:01:29Z")

</div>

![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/0/8/0873e168e7752daefffb42d0b42585a81fbdfa3f.png)

Dockerfile code:

```auto
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

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 22, 2025, 4:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpermissionerror-errno-13-permission-denied-cache%2F146951%2F2 "2025-03-22T16:08:21Z")

</div>

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…😭 perhaps @Wauplin ?

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

---

<div class="post-metadata">

**Author:** ![Senzen](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/senzen/32/35934_2.png) [@Senzen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FSenzen)%5C
**Post date:** [March 22, 2025, 4:28pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpermissionerror-errno-13-permission-denied-cache%2F146951%2F3 "2025-03-22T16:28:08Z")

</div>

you mean to set os.environ[HF\_home]

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 22, 2025, 4:34pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpermissionerror-errno-13-permission-denied-cache%2F146951%2F4 "2025-03-22T16:34:25Z")

</div>

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.

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

---

<div class="post-metadata">

**Author:** ![Wauplin](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/wauplin/32/40815_2.png) [@Wauplin](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FWauplin)%5C
**Post date:** [March 24, 2025, 9:30am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpermissionerror-errno-13-permission-denied-cache%2F146951%2F5 "2025-03-24T09:30:24Z")

</div>

You can also do that directly in your Dockerfile:

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

```
