Search code examples
pythonalpine-linux

How to install Python 3.8 on Alpine Linux not from Python base image


Specifically in this base image https://hub.docker.com/r/frolvlad/alpine-glibc/ how does one add Python 3.8 to it.. Adding python3 installs Python3.6.9. Went through How do I install python on alpine linux? but couldn't figure it out.


Solution

  • In the time of writing, the latest frolvlad/alpine-glibc image is based on Alpine 3.13.2. The current Python 3 version for Alpine 3.13 is 3.8.8. Therefore, for installing Python 3.8 simply install the python3 package. This is also true for Alpine 3.12 and 3.11.

    If you're using frolvlad/alpine-glibc based on Alpine 3.13, 3.12 or 3.11, try updating the apk database with apk update followed by apk add python3.

    On images based on older Alpine versions, such as Alpine 3.9, you'll not be able to install a functional Python 3.8, since it depends on musl 1.1.24 which is only available starting Alpine 3.10. Even though it could be installed using the Alpine 3.11+ repositories, it will fail to run due to the said musl dependency:

    / # apk add python3=3.8.2-r2 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.11/main
    fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
    (1/10) Installing libbz2 (1.0.8-r1)
    (2/10) Installing expat (2.2.9-r1)
    (3/10) Installing libffi (3.2.1-r6)
    (4/10) Installing gdbm (1.13-r1)
    (5/10) Installing xz-libs (5.2.4-r0)
    (6/10) Installing ncurses-terminfo-base (6.1_p20200118-r4)
    (7/10) Installing ncurses-libs (6.1_p20200118-r4)
    (8/10) Installing readline (8.0.1-r0)
    (9/10) Installing sqlite-libs (3.30.1-r2)
    (10/10) Installing python3 (3.8.2-r2)
    Executing busybox-1.29.3-r10.trigger
    Executing glibc-bin-2.29-r0.trigger
    OK: 71 MiB in 27 packages
    / # python3 --version
    Error relocating /usr/lib/libpython3.8.so.1.0: copy_file_range: symbol not found