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]
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.
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.
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
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With