installing PyMuPDF in python 3.8 alpine - python-3.x

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.

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

Related

Unable to install the python 3.8.5 version in nginx docker container

I am trying to install the python version 3.8.5 on the base nginx image on the Dockerfile and getting the error message. Could you please help me to resolve the issue?
FROM nginx
RUN apt-get update && \
apt-get install -y \
wget \
make \
gcc \
xxd \
curl \
libcap2-bin \
zlib1g-dev \
&& apt-get clean
RUN wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz \
&& tar -xvf Python-3.8.5.tgz && cd Python-3.8.5 \
&& ./configure --enable-shared \
&& make \
&& make test \
&& make install
Output:
FAILED (errors=1, skipped=94)
tests failed again:
test_asyncio test_socket

Unable to install latest version of chromium and chromium-chromedriver on linux (alpine3.9 docker image)

Trying to install latest version chromium and chromium-chromedriver on a python:alpine3.9 docker image. However it is installing old version. Not sure how to fix this. Please help.
Commands:
RUN apk add --update chromium>90.0.4430.24
RUN apk add --update chromium-chromedriver>90.0.4430.24
Below is the version that got installed.
bash-4.4# chromium-browser --version
Chromium 72.0.3626.121
Linux information:
bash-4.4# uname -a
Linux 53f30508846d 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 Linux
Below is the complete Dockerfile.
FROM python:alpine3.9
RUN apk update && apk add --no-cache bash \
alsa-lib \
at-spi2-atk \
atk \
cairo \
cups-libs \
dbus-libs \
eudev-libs \
expat \
flac \
gdk-pixbuf \
glib \
libgcc \
libjpeg-turbo \
libpng \
libwebp \
libx11 \
libxcomposite \
libxdamage \
libxext \
libxfixes \
tzdata \
libexif \
udev \
xvfb \
zlib-dev \
&& rm -rf /var/cache/apk/* \
/usr/share/man \
/tmp/*
RUN apk add --update chromium>90.0.4430.24
RUN apk add --update chromium-chromedriver>90.0.4430.24
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" > /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories
#RUN apk add --update py3-pip
RUN pip3 install -U selenium --trusted-host pypi.org --trusted-host files.pythonhosted.org
RUN mkdir -p /data && adduser -D chrome \
&& chown -R chrome:chrome /data

How to install aws-cli on alpine?

I'm installing aws-cli on a docker swarm manager node running alpine (Linux 0317632a4ad9 4.9.59-moby #1 SMP Thu Mar 1 20:54:00 UTC 2018 x86_64 Linux). The aws-cli package for Alpine is currently listed in the community repo on the edge branch (1.18.55.r0). I modified /etc/apk/repositories to target this repo.
The install blew up looking for py3-urllib3, but I got around that and finally got a clean install with no errors, as below:
~ $ sudo apk add aws-cli#edge-comm
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
py3-urllib3-1.25.9-r0:
masked in: #edge
satisfies: py3-botocore-1.16.12-r0[py3-urllib3<1.26]
~ $ sudo apk add py3-urllib3#edge aws-cli#edge-comm
(1/23) Installing groff (1.22.3-r1)
(2/23) Installing py3-six (1.10.0-r6)
(3/23) Installing py3-dateutil (2.6.0-r1)
(4/23) Installing libpng (1.6.37-r0)
(5/23) Installing freetype (2.7.1-r2)
(6/23) Installing libjpeg-turbo (1.5.3-r2)
(7/23) Installing lcms2 (2.8-r1)
(8/23) Installing openjpeg (2.3.0-r2)
(9/23) Installing tiff (4.0.10-r0)
(10/23) Installing libwebp (0.6.0-r0)
(11/23) Installing py3-pillow (4.1.0-r0)
(12/23) Installing py3-roman (2.0.0-r2)
(13/23) Installing py3-docutils (0.13.1-r0)
(14/23) Installing py3-jmespath#edge-comm (0.9.5-r0)
(15/23) Installing py3-urllib3#edge (1.25.9-r0)
(16/23) Installing py3-botocore#edge-comm (1.16.12-r0)
(17/23) Installing py3-s3transfer#edge-comm (0.3.3-r0)
(18/23) Installing py3-colorama#edge-comm (0.4.3-r0)
(19/23) Installing yaml (0.1.7-r0)
(20/23) Installing py3-yaml (3.12-r1)
(21/23) Installing py3-asn1 (0.2.3-r0)
(22/23) Installing py3-rsa (3.4.2-r1)
(23/23) Installing aws-cli#edge-comm (1.18.55-r0)
Executing busybox-1.26.2-r11.trigger
OK: 576 MiB in 81 packages
The binary is created at /usr/bin/aws, but crashes looking for an awscli module:
~ $ aws
Traceback (most recent call last):
File "/usr/bin/aws", line 19, in <module>
import awscli.clidriver
ModuleNotFoundError: No module named 'awscli'
Thanks!
For anybody who googles this,
I've been using the image node:12.16.1-alpine.
RUN apk add --no-cache \
python3 \
py3-pip \
&& pip3 install --upgrade pip \
&& pip3 install --no-cache-dir \
awscli \
&& rm -rf /var/cache/apk/*
RUN aws --version # Just to make sure its installed alright
# Should output aws-cli/1.18.69 etc.
Worked fine for me.
NOTE: apk --no-cache and pip3 --no-cache-dir are used to keep the Docker image lean by not retaining package cache.
We have aws-cli Alpine package now. So you can just run
apk add --no-cache aws-cli
to expand and update upon #Rose (4317383) 's answer ( and get awscli version 2 ):
the regular pip3 packet ( pip3 install awscliv2 && awscliv2 -i ) presents the following errors due to musl / non-glibc alpine implementations:
Error relocating /root/.awscliv2/binaries/aws: __strcat_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __snprintf_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __vfprintf_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __strdup: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __stpcpy_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __vsnprintf_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __strncpy_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __strcpy_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __fprintf_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __strncat_chk: symbol not found
in doubt GLIBC is necessary , but if you are willing to invest ~100MB of space or you really need v2 , the following snippet would help
RUN apk --no-cache add \
binutils \
curl \
&& GLIBC_VER=$(curl -s https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest | grep tag_name | cut -d : -f 2,3 | tr -d \",' ') \
&& curl -sL https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub \
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk \
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk \
&& apk add --no-cache \
glibc-${GLIBC_VER}.apk \
glibc-bin-${GLIBC_VER}.apk \
&& curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \
&& unzip awscliv2.zip \
&& aws/install \
&& rm -rf \
awscliv2.zip \
aws \
/usr/local/aws-cli/v2/*/dist/aws_completer \
/usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \
/usr/local/aws-cli/v2/*/dist/awscli/examples \
&& apk --no-cache del \
binutils \
curl \
&& rm glibc-${GLIBC_VER}.apk \
&& rm glibc-bin-${GLIBC_VER}.apk \
&& rm -rf /var/cache/apk/*
RUN awsv2 --version # Just to make sure its installed alright
if your scripts do not break with awscliv2 named as awscli, you might add :
RUN ln -s $(which awscliv2) /usr/bin/aws
RUN apk update \
&& apk --no-cache add curl \
&& apk --no-cache add unzip \
&& curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install
I've been using the image node:14-alpine
apk add --update --no-cache curl ca-certificates \
&& curl -sL -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& curl -sL -o glibc-2.28-r0.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk \
&& apk add glibc-2.28-r0.apk \
&& curl -sL -o glibc-bin-2.28-r0.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-bin-2.28-r0.apk \
&& apk add glibc-bin-2.28-r0.apk \
&& curl -sL -o awscliv2.zip https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.0.30.zip \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm -Rf aws/ awscliv2.zip glibc-2.28-r0.apk glibc-bin-2.28-r0.apk \
&& aws --version
Yesterday, I spent quite some time to figure out how to build a slim aws-cli v2 image for ci pipelines (hence autocomplete and examples are removed) that does not suffer from the symbol not found problem.
After the glibc 2.35-r0 packages are installed, the symlink /lib64/ld-linux-x86-64.so.2 still points to the musl version of the library and not the glibc version. In glibc 2.34-r0 the symlink was replaced correctly, so I assume it is a bug in 2.35-r0.
This is my multi-staged Dockerfile to build an aws-cli 2.7.33 image:
FROM alpine:3.16.2 as base
ENV GLIBC_VER=2.35-r0
RUN set euo pipefail; \
apk --no-cache add curl; \
curl --silent --location https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub --output /etc/apk/keys/sgerrand.rsa.pub; \
curl --silent --location --remote-name https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk; \
curl --silent --location --remote-name https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk; \
curl --silent --location --remote-name https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-i18n-${GLIBC_VER}.apk; \
apk --no-cache add \
glibc-${GLIBC_VER}.apk \
glibc-bin-${GLIBC_VER}.apk \
glibc-i18n-${GLIBC_VER}.apk; \
# optional: add if needed, will add ~10mb to the final image
#/usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8; \
# replace symlink to point to glibc version instead of musl version
ln -sf /usr/glibc-compat/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2; \
apk --no-cache del curl glibc-i18n; \
rm -rf \
/var/cache/apk/* \
/etc/apk/keys/sgerrand.rsa.pub \
glibc*${GLIBC_VER}.apk
FROM base as builder
ARG AWS_CLI_VERSION=2.7.33
RUN set euo pipefail; \
apk --no-cache add curl; \
curl --silent --location --remote-name https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip; \
unzip -q awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip; \
aws/install; \
aws --version; \
rm -rf \
awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip \
aws \
/usr/local/aws-cli/v2/*/bin/aws_completer \
/usr/local/aws-cli/v2/*/dist/aws_completer \
/usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \
/usr/local/aws-cli/v2/*/dist/awscli/examples; \
apk --no-cache del \
binutils \
curl; \
rm -rf /var/cache/apk/*
FROM base
COPY --from=builder /usr/local/aws-cli/ /usr/local/aws-cli/
RUN ln -sf /usr/local/aws-cli/v2/current/bin/aws /usr/local/bin/aws
ENTRYPOINT ["aws"]
Solution
Here's what you guys are looking for.
https://github.com/robertd/alpine-aws-cdk/blob/master/Dockerfile.v2
It works with Alpine and AWS CLI v2.
Credits for "Robert Djurasaj"
use and add apk
'''
image:
name: rxmllc/alpine-aws-cli
before_script:
- apk --no-cache add curl
'''
please refer https://hub.docker.com/r/rxmllc/alpine-aws-cli
If you are using alpine latest image then this always works for me
- apt update && apt install curl zip jq -y
# install aws cli
- curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip && unzip -q awscliv2.zip && aws/install && rm -rf awscliv2.zip aws /usr/local/aws-cli/v2/*/dist/aws_completer /usr/local/aws-cli/v2/*/dist/awscli/data/ac.index /usr/local/aws-cli/v2/*/dist/awscli/examples
# verify aws cli installation
- aws --version
you can use in my opinion alpine does not support aws cli V2
RUN apk add --no-cache \
python3 \
py3-pip \
&& pip3 install --upgrade pip \
&& pip3 install --no-cache-dir \
awscli \
&& rm -rf /var/cache/apk/*
The method published on the official awscliv2 install page for general Linux works fine on Alpine.
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip ./awscliv2.zip && \
rm -f ./awscliv2.zip && \
./aws/install -i /usr/local/aws -b /bin && \
rm -rf ./aws
Just clean up your zip and leftover install files.
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
There is an official AWS-CLI image on docker hub published by Amazon, although it uses AmazonLinux2 and not Alpine. I will recommend you use it though.
Reference:
https://hub.docker.com/r/amazon/aws-cli
It's DockerFile:
https://github.com/aws/aws-cli/blob/v2/docker/Dockerfile
FROM amazonlinux:2 as installer
COPY awscli-exe-linux-x86_64.zip .
RUN yum update -y \
&& yum install -y unzip \
&& unzip awscli-exe-linux-x86_64.zip \
# The --bin-dir is specified so that we can copy the
# entire bin directory from the installer stage into
# into /usr/local/bin of the final stage without
# accidentally copying over any other executables that
# may be present in /usr/local/bin of the installer stage.
&& ./aws/install --bin-dir /aws-cli-bin/
FROM amazonlinux:2
RUN yum update -y \
&& yum install -y less groff \
&& yum clean all
COPY --from=installer /usr/local/aws-cli/ /usr/local/aws-cli/
COPY --from=installer /aws-cli-bin/ /usr/local/bin/
WORKDIR /aws
ENTRYPOINT ["/usr/local/bin/aws"]

UnsatisfiableError: The following specifications were found to be incompatible with each other: - pip -> python[version='>=3.7,<3.8.0a0']

we are using gitlab ci/cd to integrate and deploy our projects,whenever we want to deploy our project into dev,stg,prod environments, we create fresh docker container and install all the dependencies/requirements for the project and then will deploy the code.... in this process when we run usual script, to install dependency packages and requirements we are getting the following error:
UnsatisfiableError: The following specifications were found to be incompatible with each other: - pip -> python[version='>=3.7,<3.8.0a0']
FROM python:3.6
RUN apt-get update && apt-get install --fix-missing -y \
lsof \
man \
cmake \
nano \
supervisor \
net-tools \
pv \
multitail \
bsdmainutils \
blender \
texlive-base \
texlive-latex-base \
texlive-latex-recommended \
texlive-latex-extra \
xmlsec1 \
libgl1-mesa-glx
RUN wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-
x86_64.sh \
&& bash Miniconda3-latest-Linux-x86_64.sh -bfp \
&& rm Miniconda3-latest-Linux-x86_64.sh
ENV PATH="/root/miniconda3/bin:${PATH}"
RUN conda install -n base conda -y \
&& conda install -c conda-forge -c dlr-sc -c pythonocc -c oce -c jf
pythonocc-core -y

Is sklearn compatible with Linux-alpine?

I get an error when I try to build an alpine based docker image that includes the sklearn package.
I've tried a few variations of pip installation, different package combinations, and outdated versions of sklearn to see if they are compatible. I've also run the container in -it mode and tried to install the package manually from there. When I remove the sklearn line, the Dockerfile builds and the container runs just fine. Sklearn works in an Ubuntu:latest Dockerfile I've built, but I'm trying to reduce my footprint, so I was hoping to get it to work on alpine...
Here's my Dockerfile code:
FROM alpine:latest
RUN apk upgrade --no-cache \
&& apk update \
&& apk add --no-cache \
musl \
build-base \
python3 \
python3-dev \
postgresql-dev \
bash \
git \
&& pip3 install --no-cache-dir --upgrade pip \
&& pip3 install sklearn \
&& rm -rf /var/cache/* \
&& rm -rf /root/.cache/*
And here's the error I'm getting:
ERROR: Command "/usr/bin/python3.6 /usr/lib/python3.6/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpqjsz0004" failed with error code 1 in /tmp/pip-install-xlvbli9u/scipy
Alpine Linux doesn't support PEP 513. I found that something like this works:
RUN apk add --no-cache gcc g++ gfortran lapack-dev libffi-dev libressl-dev musl-dev && \
mkdir scipy && cd scipy && \
wget https://github.com/scipy/scipy/releases/download/v1.3.2/scipy-1.3.2.tar.gz && \
tar -xvf scipy-1.3.2.tar.gz && \
cd scipy-1.3.2 && \
python3 -m pip --no-cache-dir install .

Resources