9
votes

I want to use python 3.x and pip3 to install some python libraries in docker. I used following commands to do it, but they were not installed.

FROM alpine:latest

RUN apk add python3 py3-pip3 && \
pip3 install --upgrade pip3 && \
pip3 install wget &&\
pip3 install sys &&\
pip3 install threading &&\
pip3 install time &&\
pip3 install requests &&\
pip3 install paho-mqtt &&\
pip3 install logging &&\
rm -rf /var/cache/apk/*

COPY NumSide.py /home/mehdi/Download/NumSide.py

CMD ["python3","/home/mehdi/Download/NumSide.py"]

Below, the error I got:

ERROR: unsatisfiable constraints: py3-pip3 (missing): required by: world[py3-pip3] The command '/bin/sh -c apk add python3 py3-pip3 && pip3 install --upgrade pip3 && pip3 install wget &&pip3 install sys &&pip3 install threading &&pip3 install time &&pip3 install requests &&pip3 install paho.mqtt.client &&pip3 install logging &&rm -rf /var/cache/apk/*' returned a non-zero code: 1

3
the package doesn't exist. It should be py3-pip i believe - stacksonstacks
the comment above is the correct answer, please add it as an asnwer @stacksonstacks - refex

3 Answers

22
votes

The package name is py3-pip not py3-pip3

5
votes

If you have no other considerations, following your Dockerfile I would recommend you simply use python:3-alpine base image. It s based on alpine linux, as well as yours, and already contains Python 3 stuff:

Dockerfile

FROM python:3-alpine

RUN python -m pip install --upgrade pip

RUN pip3 install requests paho-mqtt

COPY NumSide.py /home/mehdi/Download/NumSide.py

CMD ["python","/home/mehdi/Download/NumSide.py"]

Otherwise consider using apk update before installing to update the package list.

0
votes
pip3 install wget

Are you sure you want Python's wget, not system wget?

pip3 install sys &&\
pip3 install threading &&\
pip3 install time &&\
pip3 install requests &&\
pip3 install paho.mqtt.client &&\
pip3 install logging &&\

These calls could never succeed because sys, threading, time, and logging are built-in or standard modules, they cannot be installed from PyPI. And there is no such module paho.mqtt.client; perhaps you mean paho-mqtt?

As for the error py3-pip3 (missing): required by: world[py3-pip3]: [py3-pip3] in requirements means an extra requirement installed for the package. It seems world doesn't have such extra; actually it doesn't have any extras at all.