python3 and pip3 in docker
Asked Answered
R

4

11

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

Recrimination answered 16/1, 2019 at 7:22 Comment(2)
the package doesn't exist. It should be py3-pip i believeAzo
the comment above is the correct answer, please add it as an asnwer @AzoSlaby
A
23

The package name is py3-pip not py3-pip3

Azo answered 26/9, 2019 at 3:53 Comment(0)
C
5

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.

Canticle answered 16/1, 2019 at 7:41 Comment(6)
How many wrong modules can you find in pip3 install wget sys threading time requests paho.mqtt.client logging?Unconcern
@Unconcern quite a lot, really didn't even read the list and just copy pasted it from original. Thanks for notice!Canticle
when I run the docker file, I got the following error Step 2/5 : RUN pip3 install --upgrade pip3 ---> Running in 8ae8ba41c100 Collecting pip3 Could not find a version that satisfies the requirement pip3 (from versions: ) No matching distribution found for pip3 The command '/bin/sh -c pip3 install --upgrade pip3' returned a non-zero code: 1Recrimination
Edited and checked - now installation goes well.Canticle
@Unconcern I thought all the python libraries should be installed explicitly by docker, that is why I add all the modules in the docker file. I did not copy and paste from "original"Recrimination
Is there something similar for ubuntu instead of alpine?Auster
B
1

Another solution would be :

RUN apk add python3 \
     && python3 -m ensurepip \
     && pip3 install --no-cache --upgrade pip setuptools
Beeck answered 17/5, 2022 at 9:22 Comment(0)
U
0
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.

Unconcern answered 16/1, 2019 at 17:14 Comment(2)
I thought I should install all the libraries used in docker. But I realized that the docker file can use the build -in libraries of python.Recrimination
Built-in modules and modules from the standard library are automatically installed with Python. Even if they aren't (in case the distribution split the standard library in pieces) you still cannot install them with pip: pip install libraries from PyPI and those modules aren't at PyPI.Unconcern

© 2022 - 2024 — McMap. All rights reserved.