python huggingfaces空格案例中的Matplotlib权限被拒绝错误

hwazgwia  于 2023-01-01  发布在  Python
关注(0)|答案(1)|浏览(213)

我正在尝试设置huggingface空间。这是我的dockerfile

FROM python:3.9

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --prefer-binary -r /code/requirements.txt

RUN pip install --user matplotlib
COPY . .

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]

当我尝试构建它并启动它时,它给了我以下错误:

-->

===== Application Startup =====

Fetching model from: https://huggingface.co/facebook/wav2vec2-large-960h-lv60-self
Traceback (most recent call last):
  File "/usr/local/bin/uvicorn", line 8, in 
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  ......
  File "/code/./app.py", line 3, in 
    gr.Interface.load("models/facebook/wav2vec2-large-960h-lv60-self").launch()
  File "/usr/local/lib/python3.9/site-packages/gradio/interface.py", line 109, in load
    return super().load(name=name, src=src, api_key=api_key, alias=alias, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/gradio/blocks.py", line 1154, in load
    return external.load_blocks_from_repo(name, src, api_key, alias, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/gradio/external.py", line 58, in load_blocks_from_repo
    blocks: gradio.Blocks = factory_methods[src](name, api_key, alias, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/gradio/external.py", line 311, in from_model
    interface = gradio.Interface(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/gradio/interface.py", line 424, in __init__
    self.flagging_callback.setup(
  File "/usr/local/lib/python3.9/site-packages/gradio/flagging.py", line 187, in setup
    os.makedirs(flagging_dir, exist_ok=True)
  File "/usr/local/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: 'flagged'

我尝试通过添加RUN chown语句来创建文件夹并授予权限,但似乎不起作用,我该如何解决这个问题?

soat7uwm

soat7uwm1#

发生了什么?

从哪里开始:

当我遇到这个问题时,我根据互联网上的建议尝试了一些事情,这些事情对我来说 * 不 * 工作,但对你来说可能是:

  • 尝试在Docker使用这些文件之前更改它们的权限,例如使用代码目录中的chmod -R 777 .。Docker将在复制文件夹内容时复制这些文件的权限。
  • If that doesn't work (it didn't for me when I encountered this issue), you can try setting the USER in your Dockerfile and setting up a user space, as described on Huggingface here: https://huggingface.co/docs/hub/spaces-sdks-docker#permissions

完成解决方案:

以上两种方法本身对我都不起作用,但对我起作用的是:
1.将USER设置为root
1.相加RUN chmod 777 ~/app/*
为了更好地实践,我还设置了一个非root用户,并在设置权限后切换回该用户。
下面是我的项目中使用的最后一个Dockerfile,它启动了一个运行在Debian Buster Linux映像上的gradio应用程序:

FROM python:3.10-slim-buster

### Set up user with permissions
# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user

# Switch to the "user" user
USER user

# Set home to the user's home directory
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Set the working directory to the user's home directory
WORKDIR $HOME/app

# Copy the current directory contents into the container at $HOME/app setting the owner to the user
COPY --chown=user . $HOME/app

### Set up app-specific content
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

COPY . .

### Update permissions for the app
USER root
RUN chmod 777 ~/app/*
USER user

EXPOSE 7860 7860

ENTRYPOINT ["python3"]
CMD ["gradio_app.py"]

相关问题