3

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

2

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

0

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 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .