我正在尝试在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发布于 2021-03-11 15:42:15
在阿尔卑斯山中的freetype-dev将安装在/usr/include/freetype2中。您可以将头文件和目录链接到/usr/include apk add mupdf-dev安装的mupdf,方法结构与pymupdf的方法结构不一致,因此您需要从源代码编译mupdf库。
FROM python:3.8-alpine
RUN apk add gcc g++ cmake make mupdf-dev freetype-dev
ARG MUPDF=1.18.0
RUN ln -s /usr/include/freetype2/ft2build.h /usr/include/ft2build.h \
&& ln -s /usr/include/freetype2/freetype/ /usr/include/freetype \
&& wget -c -q https://www.mupdf.com/downloads/archive/mupdf-${MUPDF}-source.tar.gz \
&& tar xf mupdf-${MUPDF}-source.tar.gz \
&& cd mupdf-${MUPDF}-source \
&& make HAVE_X11=no HAVE_GLUT=no shared=yes prefix=/usr/local install \
&& cd .. \
&& rm -rf *.tar.gz mupdf-${MUPDF}-source
RUN pip install PyMuPDF==1.18.9试试这个,很管用。
此外,的官方Mupdf库已经更新,使安装更容易。(更新于2021-04-28)

FROM python:3.8-alpine
# Add temporary virtual environment dependencies
RUN apk --no-cache add --virtual .builddeps gcc g++
# These dependency packages cannot be removed because they continue to be used in PyMupdf
RUN apk --no-cache add mupdf-dev freetype-dev jbig2dec-dev jpeg-dev openjpeg-dev
# install PyMupdf
RUN pip install pymupdf
# Remove virtual environment dependencies
RUN apk del .builddeps发布于 2021-02-12 02:12:45
尝试先用pip install -U pip更新pip。
这里是一个深入的问题,有一个旧的pip,它从tar.gz文件而不是.whl获得源代码,构建失败,因为错误的freetype2包含目录,这是从PyMuPDF 1.18.2开始解决的,但是...Pypi的源tar.gz已过期。
发布于 2020-12-21 17:30:11
对于这些类型的错误,有一些简单的步骤可以采取:
apk将其安装在done文件中,您就可以开始使用<代码>G212
在您的例子中,这是在阿尔卑斯山版本3.12上搜索的结果:

因此,在现有的apk命令中添加软件包freetype-dev可以修复您的问题
RUN apk add --no-cache \
freetype-devhttps://stackoverflow.com/questions/65388430
复制相似问题