Unable to write in cache folder

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

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:

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?

1 Like

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

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

1 Like

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.