I want to build a python docker container that has scikit-learn, opencv, and numpy. Unfortunately, I couldn't find a pre-built container that contained all these, but I did find the one below that contains numpy and scikit-learn.
https://hub.docker.com/r/frolvlad/alpine-python-machinelearning/
I still needed to install opencv, so within my docker file I included a RUN pip install opencv-python
. However, I keep on getting the error below:
Could not find a version that satisfies the requirement opencv-python (from version: )
No matching distribution found for opencv-python
Every single thing I have read online says that a pip install opencv-python
will work, but it isn't working for me for some reason. Is it a problem with the python package maybe?
Any help is appreciated
Also, I will include my full Dockerfile below, I am aiming to use openFaas, which is a serverless framework, so my Dockerfile might look odd:
FROM frolvlad/alpine-python-machinelearning
RUN apk update
RUN apk upgrade
# Alternatively use ADD https:// (which will not be cached by Docker builder)
RUN apk --no-cache add curl \
&& echo "Pulling watchdog binary from Github." \
&& curl -sSL
https://github.com/openfaas/faas/releases/download/0.8.0/fwatchdog > /usr/bin/fwatchdog \
&& chmod +x /usr/bin/fwatchdog \
&& apk del curl --no-cache
# Add non root user
RUN addgroup -S app && adduser -S -g app app
RUN chown app /home/app
RUN pip install -U pip
USER app
ENV PATH=$PATH:/home/app/.local/bin
WORKDIR /home/app/
RUN pip install opencv-python
RUN mkdir -p function
RUN touch ./function/__init__.py
WORKDIR /home/app/function/
RUN pip install --user app opencv-python
WORKDIR /home/app/
COPY function function
ENV fprocess="python index.py"
HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1
CMD ["fwatchdog"]
With this container, you can simply run pip install opencv-python numpy scipy to have all three of your desired packages installed. The rest of your Dockerfile should work mostly unmodified; you will just need to install/uninstall curl using apt instead of apk.
If you are stuck with OpenCV installation or if you want to try out the new OpenCV-3.4.4 and OpenCV-4.0 ( released on 20th November 2018 ), without actually installing it on your system, this docker image is the perfect match for you. Section 1: How to install Docker on Linux, MacOS and Windows.
In addition to OpenCV, the image also has dlib and a Facial Landmark Detection example code. Every day we receive a few emails and comments on our posts about OpenCV and Dlib installation.
It turns out that this is not working because opencv-python does not have any prebuilt wheels for Alpine (the distribution you're using as your base docker image). The conversation in this issue on the opencv-python package explains why this happens in greater detail.
I've just run into this issue as well. It turns out that this is not working because opencv-python
does not have any prebuilt wheels for Alpine (the distribution you're using as your base docker image).
The conversation in this issue on the opencv-python
package explains why this happens in greater detail. The TL;DR is: if you really need to use Alpine, you can try forcing the installation of the manylinux wheel for opencv-python
, but this can break. Your best option if you need to keep Alpine is to build the module from source. Since you are running this on OpenFAAS, I suspect you will want to keep your size low, so building from source may be a good option for you.
If you're not attached to Alpine, I would suggest moving to a different base docker image. If you're not sure which image to use as your base, I would recommend python:3.7-slim
, since it will come with Python already installed (substitute 3.7
for whichever version you are using, but really. . . 3.7 is nice). With this container, you can simply run pip install opencv-python numpy scipy
to have all three of your desired packages installed. The rest of your Dockerfile should work mostly unmodified; you will just need to install/uninstall curl
using apt
instead of apk
.
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