8

I am using docker's official docker image and want to install python3.9.6

Running this installs python 3.10.x

apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python

and I can't figure out how to specify exact version of python I want to install.

Please don't suggest using docker images with python preinstalled

    3 Answers 3

    4

    I tried many answers from different sources, eventually I copied the repository file and checked the naming convention by extracting the compressed file :

    $ wget https://dl-cdn.alpinelinux.org/alpine/edge/main/aarch64/APKINDEX.tar.gz $ tar -xvf APKINDEX.tar.gz $ cat APKINDEX | grep python3 

    and the found the line.

    D:python3 python3~3.11 

    and the following worked

    apk --update --no-cache add python3~3.11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main 
    1
    • This doesn't work if you target edge in the --repository argument. Because edge will always get updated (for example it's now on python 3.12 so the line you provided doesn't work). You should instead target v3.18 or v3.19 for python 3.11. But I'm not sure how stable that is. FWIW 3.18 was updated today but still contains 3.11 instead of 3.12, despite it being available.
      – Nickolai
      CommentedMar 19 at 4:02
    3

    You did not specify which tag you are using for the image from https://hub.docker.com/_/docker, but your question specifies Alpine so I will try to explain that.

    There is usually only one packaged version of Python in any given version of Alpine.

    The most recent Alpine v3.16 has packaged Python v3.10.5.

    You can get Python v3.9.5 by using Alpine 3.14 or Python v3.9.13 by using Alpine 3.15

    I do not see that Python v3.9.6 has been packaged for any version of Alpine.

    You should be able to change the tag for the image from https://hub.docker.com/_/docker to match the desired version of Alpine.

    If you really need to use Python v3.9.6, your best option may be to use one of the official Docker Python images and specifying one of the 3.9.6 tags

      2

      There are virtual environment software packages with features for installing and managing different versions of Python. Some can even install more than one version at a time and switch between versions at will.

      The two I've used for Python are virtualenv and pyenv. They're Open Source Software (OSS) projects, but they have reasonably simple steps to install:

      Virtualenv: https://pypi.org/project/virtualenv/
      Pyenv: https://github.com/pyenv/pyenv

        You must log in to answer this question.

        Start asking to get answers

        Find the answer to your question by asking.

        Ask question

        Explore related questions

        See similar questions with these tags.