django/python docker libreoffice子进程

发布于 2025-02-03 15:07:47 字数 1662 浏览 1 评论 0原文

我正在尝试在Django应用中使用Libreoffice,以使用Python Subocess将DOCX文件转换为PDF。

中包括了Libreoffice

我在Dockerfile: Dockerfile

FROM python:3.8-alpine

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /requirements.txt
COPY ./behavioursolutiondjango /behavioursolutiondjango
COPY ./scripts /scripts

WORKDIR /behavioursolutiondjango
EXPOSE 8000

RUN python -m venv /py && \
    /py/bin/pip install --upgrade pip && \
    apk add --update python3-dev \
                          xmlsec xmlsec-dev \
                          gcc \
                          libc-dev \
                          libreoffice \
                          libffi-dev && \
    apk add --update --no-cache postgresql-client && \
    apk add --update --no-cache --virtual .tmp-deps \
        build-base postgresql-dev musl-dev linux-headers && \
    /py/bin/pip install -r /requirements.txt && \
    apk del .tmp-deps && \
    adduser --disabled-password --no-create-home app && \
    mkdir -p /vol/web/static && \
    mkdir -p /vol/web/media && \
    chown -R app:app /vol && \
    chmod -R 755 /vol && \
    chmod -R +x /scripts

ENV PATH="/scripts:/py/bin:$PATH"

USER app

CMD ["run.sh"]

:并进行以下运行以进行转换:

subprocess.call(["soffice", "--headless", "--convert-to", "pdf", new_cert.cert.path])

但是我遇到了以下错误:

LibreOffice 7.2 - Fatal Error: The application cannot be started. 
User installation could not be completed. 

我已经花了几个小时了,无法弄清楚我缺少什么。

我很乐意使用Libreoffice以外的其他东西,但是除了Libreoffice以外,找不到可以起作用的东西。

I am trying to use libreoffice in my Django app, to convert a docx file to pdf using python subprocess.

I have included libreoffice in my dockerfile:

Dockerfile:

FROM python:3.8-alpine

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /requirements.txt
COPY ./behavioursolutiondjango /behavioursolutiondjango
COPY ./scripts /scripts

WORKDIR /behavioursolutiondjango
EXPOSE 8000

RUN python -m venv /py && \
    /py/bin/pip install --upgrade pip && \
    apk add --update python3-dev \
                          xmlsec xmlsec-dev \
                          gcc \
                          libc-dev \
                          libreoffice \
                          libffi-dev && \
    apk add --update --no-cache postgresql-client && \
    apk add --update --no-cache --virtual .tmp-deps \
        build-base postgresql-dev musl-dev linux-headers && \
    /py/bin/pip install -r /requirements.txt && \
    apk del .tmp-deps && \
    adduser --disabled-password --no-create-home app && \
    mkdir -p /vol/web/static && \
    mkdir -p /vol/web/media && \
    chown -R app:app /vol && \
    chmod -R 755 /vol && \
    chmod -R +x /scripts

ENV PATH="/scripts:/py/bin:$PATH"

USER app

CMD ["run.sh"]

And have the following running to do the conversion:

subprocess.call(["soffice", "--headless", "--convert-to", "pdf", new_cert.cert.path])

But I am running into the following error:

LibreOffice 7.2 - Fatal Error: The application cannot be started. 
User installation could not be completed. 

I have spent hours on this and cannot figure out what im missing.

I would be more than happy to use something other than Libreoffice, but cannot find something that will work, other than libreoffice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文