Skip to content

Instantly share code, notes, and snippets.

@orenitamar
Last active March 22, 2024 05:13
Show Gist options
  • Save orenitamar/f29fb15db3b0d13178c1c4dd611adce2 to your computer and use it in GitHub Desktop.
Save orenitamar/f29fb15db3b0d13178c1c4dd611adce2 to your computer and use it in GitHub Desktop.
Installing numpy, scipy, pandas and matplotlib in Alpine (Docker)
# Below are the dependencies required for installing the common combination of numpy, scipy, pandas and matplotlib
# in an Alpine based Docker image.
FROM alpine:3.4
RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk --no-cache --update-cache add gcc gfortran python python-dev py-pip build-base wget freetype-dev libpng-dev openblas-dev
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h
RUN pip install numpy scipy pandas matplotlib
@pPanda-beta
Copy link

In case you cant move to slim-buster, the natural answer to this is
pip install --extra-index-url https://alpine-wheels.github.io/index ...

@samanthahw21
Copy link

Hi, can anyone help. I tried to execute the line in the Docker file but it takes very long to run .
Can anyone can help and what should i do ?
i didn't include panda version in my requirements - i tried but it run error . should i include and what version ? thanks

Pull a pre-built alpine docker image with nginx and python3 installed

FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7
ENV LISTEN_PORT=8000
EXPOSE 8000
COPY /app /app
RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk --no-cache --update-cache add gcc gfortran python python-dev py-pip build-base wget freetype-dev libpng-dev openblas-dev
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h
RUN pip install pandas

@Frikster
Copy link

Thanks @orenitamar.

@mkdthanga: The following worked for me - I simply used python3-alpine build, and removed python, python-dev and py-pip from the apk command (line 5, OP):

FROM python:3-alpine
WORKDIR /usr/source/app
COPY requirements.txt ./

RUN apk update
RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk --no-cache --update-cache add gcc gfortran build-base wget freetype-dev libpng-dev openblas-dev
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h
RUN pip install --no-cache-dir -r requirements.txt

This leads to ERROR: Failed building wheel for pyarrow for me

@PaleNeutron
Copy link

PaleNeutron commented Jul 19, 2022

@Frikster If you are using python:3-alpine which means you prefer the latest python3.10 version, you could consider using package from alpine instead of from pip.

This way need python package from alpine!!!!

FROM alpine:3.16
RUN apk --no-cache --update-cache add  python3 py3-pip py3-arrow  py3-pandas # and py3-anything package need to be compiled
RUN pip install --no-cache-dir -r requirements.txt

@Tejas9019
Copy link

=> ERROR [6/8] RUN apk --no-cache --update-cache add gcc gfortran python python-dev py-pip build-base wget freetype-dev libpng-dev openblas-dev 5.3s

[6/8] RUN apk --no-cache --update-cache add gcc gfortran python python-dev py-pip build-base wget freetype-dev libpng-dev openblas-dev:
nity/x86_64/APKINDEX.tar.gz
#11 5.137 WARNING: Ignoring http://dl-8.alpinelinux.org/alpine/edge/community: DNS lookup error
#11 5.215 ERROR: unable to select packages:
#11 5.252 python (no such package):
#11 5.252 required by: world[python]
#11 5.252 python-dev (no such package):
#11 5.252 required by: world[python-dev]


executor failed running [/bin/sh -c apk --no-cache --update-cache add gcc gfortran python python-dev py-pip build-base wget freetype-dev libpng-dev openblas-dev]: exit code: 2

I am getting error like this pls can anyone help me out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment