Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install python on alpine linux?

How do I install python3 and python3-pip on an alpine based image (without using a python image)?

 $ apk add --update python3.8 python3-pip  ERROR: unsatisfiable constraints:    python3-pip (missing):      required by: world[python3-pip]    python3.8 (missing):      required by: world[python3.8] 
like image 431
Cutaraca Avatar asked Jun 24 '20 12:06

Cutaraca


People also ask

Can alpine run Python?

Don't use Alpine Linux for Python images Unless you want massively slower build times, larger images, more work, and the potential for obscure bugs, you'll want to avoid Alpine Linux as a base image. For some recommendations on what you should use, see my article on choosing a good base image.

How do I install python 3.10 on Linux?

Install the required dependency for adding custom PPAs. Then proceed and add the deadsnakes PPA to the APT package manager sources list as below. Press Enter to continue. With the deadsnakes repository added to your Ubuntu 20.04|18.04 system, now download Python 3.10 with the single command below.


2 Answers

This is what I use in a Dockerfile for an alpine image:

# Install python/pip ENV PYTHONUNBUFFERED=1 RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python RUN python3 -m ensurepip RUN pip3 install --no-cache --upgrade pip setuptools 
like image 113
Terry Spotts Avatar answered Sep 29 '22 21:09

Terry Spotts


Look here: https://pkgs.alpinelinux.org/packages So what you are looking for are the python3 and py3-pip packages.

A suitable command to use inside a dockerfile/etc would be:

apk add --no-cache python3 py3-pip 

Explanation of the --no-cache flag

Note however, that you need to add the community repository since py3-pip is not present on main.

like image 36
Linus H. Avatar answered Sep 29 '22 21:09

Linus H.