1

I am trying to install PyMuPDF in the official Python 3.8 alpine docker image. The dockerfile is like this:

FROM python:3.8-alpine

RUN apk add --update --no-cache \
    gcc g++ \
    libc-dev \
    python3-dev \
    build-base \
    cairo-dev \
    cairo \
    cairo-tools \
    jpeg-dev \
    zlib-dev \
    freetype-dev \
    lcms2-dev \
    openjpeg-dev \
    tiff-dev \
    tk-dev \
    tcl-dev \
    mupdf-dev \
    musl-dev \
    jbig2dec \
    openjpeg-dev \
    harfbuzz-dev \
    vim bash

COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --cache-dir .pip-cache -r requirements.txt && \
    rm -rf .pip-cache

The version of PyMuPDF I'm trying to install is 1.20.1

Attempts to build this image is failing with this error:

#10 137.0 × Encountered error while trying to install package.
#10 137.0 ╰─> PyMuPDF

As I understand, a PyMuPDF wheel for Alpine linux is not available. That's why we have to make it from source. Scrolling up a bit in the the terminal, I see this:

#10 124.9       scripts/tesseract/endianness.h:20:2: error: #error "I don't know what architecture this is!"
#10 124.9          20 | #error "I don't know what architecture this is!"
#10 124.9             |  ^~~~~
#10 124.9       make: *** [Makefile:133: build/release/source/fitz/tessocr.o] Error 1

So looks like building PyMuPDF fails because tesseract cannot recognize the endianness of this environment. How can I move past this hurdle?

If you have a working example of installing PyMuPDF in this docker image, please let me know. Thanks in advance.

Raiyan
  • 1,589
  • 1
  • 14
  • 28
  • Does this help https://github.com/pymupdf/PyMuPDF/discussions/1015? – β.εηοιτ.βε Jun 30 '22 at 15:11
  • Thanks for your comment @β.εηοιτ.βε, I already went through that discussion on github. I saw two working solutions there, both are for ubuntu/debian. But I need to make this work for the Alpine OS. Also, a point to note, I haven't seen anyone else mentioning this endianness related error. – Raiyan Jun 30 '22 at 19:11

1 Answers1

1

Here is an example with Python 3.10 Alpine. Not 3.8 but I hope this helps.

FROM python:3.10-alpine3.16

ARG PYMUPDF_VERSION=1.20.1

RUN apk update \
    && apk add --update --no-cache \
        build-base \
        gcc \
        jbig2dec \
        jpeg-dev \
        harfbuzz-dev \
        libc-dev \
        mupdf-dev \
        musl-dev \
        openjpeg-dev \
        swig \
    && ln -s /usr/lib/libjbig2dec.so.0 /usr/lib/libjbig2dec.so

WORKDIR /tmp

RUN wget https://github.com/pymupdf/PyMuPDF/archive/refs/tags/${PYMUPDF_VERSION}.tar.gz \
    && tar -xzf ${PYMUPDF_VERSION}.tar.gz \
    && rm ${PYMUPDF_VERSION}.tar.gz \
    && cd PyMuPDF-${PYMUPDF_VERSION} \
    && python setup.py build && python setup.py install
mboivin
  • 11
  • 1