I tried installing opencv-contrib-python but I'm unable to get it to work on docker. It says Could not find a version that satisfies the requirement opencv-contrib-python
I tried,
pip install opencv-contrib-python-headless
Then, I tired https://github.com/cassiobotaro/docker-opencv-contrib/blob/master/Dockerfile and I also tried,
FROM python:3.5-alpine
COPY . /app
WORKDIR /app
RUN apk add --no-cache ca-certificates
RUN apk add --no-cache git build-base musl-dev alpine-sdk cmake clang clang-dev make gcc g++ libc-dev linux-headers
RUN mkdir /tmp/opencv
WORKDIR /tmp/opencv
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.1.zip
RUN unzip opencv.zip
RUN wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.1.zip
RUN unzip opencv_contrib.zip
RUN mkdir /tmp/opencv/opencv-3.4.1/build
WORKDIR /tmp/opencv/opencv-3.4.1/build
RUN cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/tmp/opencv/opencv_contrib-3.4.1/modules -D BUILD_DOCS=OFF BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_opencv_java=OFF -D BUILD_opencv_python=OFF -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=OFF ..
RUN make -j4
RUN make install
RUN rm -rf /tmp/opencv
RUN pip3 install -r requirements.txt
CMD ["app.py"]
But I cannot get either one of it to work. PLease let me know how can I install the above in docker by just the requirements file?
More references (Things that I've tried) : Unable to install/run docker with opencv
and
I had the same issue. I was using python-slim. It occurs due to run time dependencies. Add the following code snippet in your DockerFile to install run time dependencies.
Install OpenCV's runtime dependencies
RUN apt-get update RUN apt-get -y install libglib2.0-0 RUN apt-get -y install libsm6 \ libxrender-dev \ libxext6
My guess is that you're seeing the failure on the
-alpine
version because theopencv
package is a binary distribution (it's not just Python code), and it probably hasn't been built for Alpine. Alpine uses a C library that is different from everything else (Alpine uses MUSL libc while just about everthing else uses Glibc); there is some possibility that the opencv codebase won't even build for MUSL. Or maybe it's just that nobody has gotten around to building a binary package. In either case, you're better off with one of the following options:If I use the stock python:3.5 image (not the Alpine one) it Just Works:
If I use the
3.5-slim
tag, I see the same error you reported:As we can see from a package query, that library is owned by the
libglib2.0
package, which is apparently not installed by default in the-slim
version of the Python image. We can fix that:And now it runs as expected:
You could build your own image incorporating this fix using a
Dockerfile
like:Update
Regarding your comment: if you want a package to be available to code running in your container then, yes, you have to install it. Where else will it come from?
If
opencv-contrib-python-headless
is included in yourrequirements.txt
, then what have posted in the comments should work just fine:If you
requirements.txt
does not include this (why not?), you would need to explicitly install it: