# Unable to write in cache folder

**URL:** <https://discuss.huggingface.co/t/unable-to-write-in-cache-folder/129303>\
**Category:** Spaces\
**Created:** [December 4, 2024, 11:51pm UTC](https://discuss.huggingface.co/t/unable-to-write-in-cache-folder/129303 "2024-12-04T23:51:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![melnnnnn](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@melnnnnn](https://discuss.huggingface.co/u/melnnnnn)\
**Post date:** [December 4, 2024, 11:51pm UTC](https://discuss.huggingface.co/t/unable-to-write-in-cache-folder/129303/1 "2024-12-04T23:51:20Z")

</div>

I want to deploy my app on HuggingFaceSpaces but encountered an error:

```auto
There was a problem when trying to write in your cache folder (/.cache/huggingface/hub). You should set the environment variable TRANSFORMERS_CACHE to a writable directory.
[nltk_data] Downloading package punkt to /nltk_data...
Traceback (most recent call last):
  File "/APP/rag_lchain.py", line 19, in <module>
    nltk.download('punkt')
  File "/usr/local/lib/python3.12/site-packages/nltk/downloader.py", line 774, in download
    for msg in self.incr_download(info_or_id, download_dir, force):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/nltk/downloader.py", line 642, in incr_download
    yield from self._download_package(info, download_dir, force)
  File "/usr/local/lib/python3.12/site-packages/nltk/downloader.py", line 698, in _download_package
    os.makedirs(download_dir, exist_ok=True)
  File "<frozen os>", line 225, in makedirs
PermissionError: [Errno 13] Permission denied: '/nltk_data'
There was a problem when trying to write in your cache folder (/.cache/huggingface/hub). You should set the environment variable TRANSFORMERS_CACHE to a writable directory.
[nltk_data] Downloading package punkt to /nltk_data...
Traceback (most recent call last):
  File "/APP/rag_lchain.py", line 19, in <module>
    nltk.download('punkt')
  File "/usr/local/lib/python3.12/site-packages/nltk/downloader.py", line 774, in download
    for msg in self.incr_download(info_or_id, download_dir, force):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/nltk/downloader.py", line 642, in incr_download
    yield from self._download_package(info, download_dir, force)
  File "/usr/local/lib/python3.12/site-packages/nltk/downloader.py", line 698, in _download_package
    os.makedirs(download_dir, exist_ok=True)
  File "<frozen os>", line 225, in makedirs
PermissionError: [Errno 13] Permission denied: '/nltk_data'

```

My Dockerfile:

```auto
FROM python:3.12

WORKDIR /APP

COPY requirements.txt .

COPY sparse_encoder.json .

COPY README.md .

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

COPY rag_lchain.py .

EXPOSE 7860

ENV GRADIO_SERVER_NAME="0.0.0.0"

CMD ["python", "rag_lchain.py"]

```

What I can do to fix this problem?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [December 5, 2024, 12:09am UTC](https://discuss.huggingface.co/t/unable-to-write-in-cache-folder/129303/2 "2024-12-05T00:09:28Z")

</div>

This is an error that appears when trying to install Python 3.12 on HF Spaces. Please use Python 3.11 or 3.10.

---

<div class="post-metadata">

**Author:** ![melnnnnn](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@melnnnnn](https://discuss.huggingface.co/u/melnnnnn)\
**Post date:** [December 5, 2024, 1:21am UTC](https://discuss.huggingface.co/t/unable-to-write-in-cache-folder/129303/3 "2024-12-05T01:21:48Z")

</div>

I tried using python 3.11 and 3.10 and this unfortunately didn’t help

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [December 5, 2024, 1:25am UTC](https://discuss.huggingface.co/t/unable-to-write-in-cache-folder/129303/4 "2024-12-05T01:25:19Z")

</div>

If that’s the case, it’s probably a library error… If it’s as per the error message, it should be fine, but it’s rare that things go as per the error message.

> **[How to Change Hugging Face Transformers Default Cache Directory - GeeksforGeeks](https://www.geeksforgeeks.org/how-to-change-hugging-face-transformers-default-cache-directory/)**
>
> Changing the default cache directory for Hugging Face Transformers can help manage space, organize models, and facilitate collaboration, and it can be done programmatically, via command line, or through configuration files.
