无法在 alpine docker 镜像上安装 PyMuPDF

时间:2020-12-21 06:34:14

标签: python docker alpine pymupdf

我正在尝试在 apline 图像上安装 pymupdf 包,但出现以下错误

fitz/fitz_wrap.c:2739:10: fatal error: ft2build.h: No such file or directory
     2739 | #include <ft2build.h>
          |          ^~~~~~~~~~~~
    compilation terminated.
    error: command 'gcc' failed with exit status 1
 RUN pip install PyMuPDF
 ---> Running in 34d246d6f01b
Collecting PyMuPDF
  Downloading PyMuPDF-1.18.5.tar.gz (251 kB)
Using legacy 'setup.py install' for PyMuPDF, since package 'wheel' is not installed.
Installing collected packages: PyMuPDF
    Running setup.py install for PyMuPDF: started
    Running setup.py install for PyMuPDF: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-uxc_zm2j/pymupdf/setup.py'"'"'; __file__='"'"'/tmp/pip-install-uxc_zm2j/pymupdf/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-nipvlcn8/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.8/PyMuPDF
         cwd: /tmp/pip-install-uxc_zm2j/pymupdf/
    Complete output (20 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.8
    creating build/lib.linux-x86_64-3.8/fitz
    copying fitz/__init__.py -> build/lib.linux-x86_64-3.8/fitz
    copying fitz/fitz.py -> build/lib.linux-x86_64-3.8/fitz
    copying fitz/utils.py -> build/lib.linux-x86_64-3.8/fitz
    copying fitz/__main__.py -> build/lib.linux-x86_64-3.8/fitz
    running build_ext
    building 'fitz._fitz' extension
    creating build/temp.linux-x86_64-3.8
    creating build/temp.linux-x86_64-3.8/fitz
    gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/mupdf -I/usr/local/include/mupdf -Imupdf/thirdparty/freetype/include -I/usr/include/python3.8 -c fitz/fitz_wrap.c -o build/temp.linux-x86_64-3.8/fitz/fitz_wrap.o
    fitz/fitz_wrap.c:2739:10: fatal error: ft2build.h: No such file or directory
     2739 | #include <ft2build.h>
          |          ^~~~~~~~~~~~
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-uxc_zm2j/pymupdf/setup.py'"'"'; __file__='"'"'/tmp/pip-install-uxc_zm2j/pymupdf/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-nipvlcn8/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.8/PyMuPDF Check the logs for full command output.
WARNING: You are using pip version 20.2.4; however, version 20.3.3 is available.
You should consider upgrading via the '/usr/bin/python3.8 -m pip install --upgrade pip' command.
The command '/bin/sh -c pip install PyMuPDF' returned a non-zero code: 1

5 个答案:

答案 0 :(得分:3)

Alpine 中的 freetype-dev 将安装在 /usr/include/freetype2 中。您可以将标题和目录链接到 /usr/include var x = moment('12/30/2014 16:26:31 MSK', "MM/dd/yyyy HH:mm:ss zzz"); var y = moment('12/31/2014 06:46:23 MSK', "MM/dd/yyyy HH:mm:ss zzz"); console.log(x.isValid()); // false console.log(y.isValid()); // false console.log(x.isAfter(y)); // false console.log(x.isBefore(y)); // false console.log(x.isSame(y)); // false var xWithoutZZZ = moment('12/30/2014 16:26:31', "MM/dd/yyyy HH:mm:ss"); var yWithoutZZZ = moment('12/31/2014 06:46:23', "MM/dd/yyyy HH:mm:ss"); console.log(xWithoutZZZ.isValid()); // true console.log(yWithoutZZZ.isValid()); // true console.log(xWithoutZZZ.isAfter(yWithoutZZZ)); // true ???? WTF WHY console.log(xWithoutZZZ.isBefore(yWithoutZZZ)); // false console.log(xWithoutZZZ.isSame(yWithoutZZZ)); // false 安装的mupdf方法结构与pymupdf不一致,所以需要从源码编译mupdf库。

apk add mupdf-dev

试试这个,它有效

答案 1 :(得分:1)

首先尝试使用 pip install -U pip 更新 pip。

这是对问题的深入探讨https://github.com/pymupdf/PyMuPDF/issues/894 有一个旧 pip 从 tar.gz 文件而不是 .whl 获取源代码,并且构建失败,因为 freetype2 的 INCLUDE 目录错误,自 PyMuPDF 1.18 以来已解决。 2 但是... Pypi 的源 tar.gz 已过时。

答案 2 :(得分:0)

对于这些类型的错误,可以采取简单的步骤:

  1. 阅读错误并确定丢失的文件,您已经完成了,您似乎丢失了ft2build.h
  2. 转到 Alpine package website 并浏览 Contents 标签
  3. 文件字段中输入您丢失的文件的名称;在 Branch 中,选择您的 Alpine 版本,然后在 Repository 中选择 main
  4. 这将指向一个特定的包,只需通过 Dockerfile 中的 apk 安装它,然后就可以了

就您而言,这是对 Alpine 3.12 版进行此类搜索的结果: Alpine contents search

因此您可以在现有的 apk 命令中添加包 freetype-dev

来修复您的问题
RUN apk add --no-cache \
      freetype-dev

答案 3 :(得分:0)

问题是 PyPI 上没有针对 docker 文件建立的环境的轮子。 在这种情况下,pip 会尝试从源创建 PyMuPDF。 因为 PyMuPDF 是 MuPDF 的绑定,当没有安装 MuPDF 时,这反过来必然会失败......就像这里。 因此,解决方案是

  • 在安装 PyMuPDF 之前先安装 MuPDF
  • 或使用有轮子的操作系统/Python 组合之一。

答案 4 :(得分:0)

这对我有用,并且只适用于 python:3.8.10 或更高版本和 Pymupdf:1.18.14:

1)。仅当您没有安装 python 时:
apk add --update py-pip

2)。安装依赖项:

apk add --no-cache \
python3-dev \
mupdf-dev \
gcc \
libc-dev \
musl-dev \
jbig2dec \
openjpeg-dev \
jpeg-dev \
harfbuzz-dev

3)。创建快捷方式:
ln -s /usr/lib/libjbig2dec.so.0 /usr/lib/libjbig2dec.so

4)。安装 PymuPdf:
pip install pymupdf

仅当您想同时进行时

apk add --update py-pip \
&& apk add --no-cache \
python3-dev \
mupdf-dev \
gcc \
libc-dev \
musl-dev \
jbig2dec \
openjpeg-dev \
jpeg-dev \
harfbuzz-dev \
&& ln -s /usr/lib/libjbig2dec.so.0 /usr/lib/libjbig2dec.so \
&& pip install pymupdf