如何在docker上为python3.5安装openCV(debian:jessie)

时间:2018-09-23 06:43:43

标签: opencv docker python-3.5 debian-jessie

我已经为此苦苦挣扎了几天,找不到在debian:jessie docker上安装OpenCV + python3.5的正确方法(我不能在debian:jessie旁边使用任何基础映像)。

我目前正在尝试纠结的怪兽,因为您会发现波纹管很深。

我主要基于以下方式处理许多错误: https://www.pyimagesearch.com/2017/09/25/configuring-ubuntu-for-deep-learning-with-python/ https://github.com/janza/docker-python3-opencv/blob/master/Dockerfile

我认为我的问题是安装python3.5,并将pip3设置为默认值,然后通过它安装numpy,然后再安装其余的。但是目前我还不确定,也不确定如何解决。

真的可以使用任何帮助和指针来解决此问题。 谢谢。

FROM debian:jessie
RUN mkdir -p /home/deployer
RUN apt-get update && apt-get install -yq libgconf-2-4 && apt-get install vim -y
RUN apt-get update && apt-get install -y wget --no-install-recommends \
    && apt-get install -y curl \
    && apt-get install -y libssl-dev openssl \
    && apt-get install -y software-properties-common \
    && apt-get install -y python-dev build-essential \
    && apt-get install -y python-setuptools \
    && easy_install pip \
    && apt-get install -y python3-pip \
    && apt-get install -y python \
    && wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz \
    && tar xzvf Python-3.5.0.tgz \
    && cd Python-3.5.0 \
    && ./configure \
    && make \
    && make install \
    && cd /home/deployer/ \
    && apt-get update \
    && apt-get upgrade -y \
    && apt-get install -y p7zip \
    && apt-get install -y p7zip-full \
    && apt-get install -y unace \
    && apt-get install -y zip \
    && apt-get install -y unzip \
    && apt-get install -y xz-utils \
    && apt-get install -y sharutils \
    && apt-get install -y build-essential cmake pkg-config \
    && apt-get install -y libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev \
    && apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
    && apt-get install -y libxvidcore-dev libx264-dev \
    && apt-get install -y libgtk2.0-dev libgtk-3-dev \
    && apt-get install -y libatlas-base-dev gfortran \
    && apt-get install -y python2.7-dev python3-dev \
    && wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.3.0.zip \
    && wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.3.0.zip \
    && wget https://bootstrap.pypa.io/get-pip.py \
    && python get-pip.py \
    && python3 get-pip.py \
    && pip install numpy \
    && pip3 install numpy \
RUN cd /home/deployer/ \
    && unzip opencv.zip \
    && unzip opencv_contrib.zip \
    && cd /home/deployer/opencv-3.3.0/ \
    && mkdir build \
    && cd build \
    && cmake -D CMAKE_BUILD_TYPE=RELEASE \
     -D CMAKE_INSTALL_PREFIX=/usr/local \
     -D INSTALL_C_EXAMPLES=ON \
     -D INSTALL_PYTHON_EXAMPLES=ON \
     -D OPENCV_EXTRA_MODULES_PATH=/home/deployer/opencv_contrib-3.3.0/modules \
     -D BUILD_EXAMPLES=ON \
     -D WITH_TBB=ON \
     -D WITH_V4L=ON \
     -D INSTALL_C_EXAMPLES=ON \
     -D PYTHON_EXECUTABLE=/usr/local/bin/python3.5 \
     -D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so \
     -D PYTHON_INCLUDE_DIR=/usr/include/python3.5m/ \
     -D PYTHON_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python3.5m/ \
     -D PYTHON_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include/ \
     -D BUILD_opencv_java=OFF .. \
    && make -j4 \
    && make install \
    && ldconfig
RUN pip3 install Pillow

1 个答案:

答案 0 :(得分:3)

在Dockerfile下面,使用pip默认安装python3.5,并在 debian:jessie 基础映像中安装openCV 3.4.2。这样可以解决您的问题。

mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        // use keyEvent
        return false;
    }
});

python版本:

FROM debian:jessie
ENV PATH /usr/local/bin:$PATH
ENV LANG C.UTF-8
RUN apt-get update && apt-get install -y --no-install-recommends \
        ca-certificates \
        netbase \
    && rm -rf /var/lib/apt/lists/*

ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D
ENV PYTHON_VERSION 3.5.6
RUN set -ex \
    \
    && savedAptMark="$(apt-mark showmanual)" \
    && apt-get update && apt-get install -y --no-install-recommends \
        dpkg-dev \
        gcc \
        libbz2-dev \
        libc6-dev \
        libexpat1-dev \
        libffi-dev \
        libgdbm-dev \
        liblzma-dev \
        libncursesw5-dev \
        libreadline-dev \
        libsqlite3-dev \
        libssl-dev \
        make \
        tk-dev \
        wget \
        xz-utils \
        zlib1g-dev \
        $(command -v gpg > /dev/null || echo 'gnupg dirmngr') \
    \
    && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
    && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
    && export GNUPGHOME="$(mktemp -d)" \
    && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
    && gpg --batch --verify python.tar.xz.asc python.tar.xz \
    && { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \
    && rm -rf "$GNUPGHOME" python.tar.xz.asc \
    && mkdir -p /usr/src/python \
    && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
    && rm python.tar.xz \
    \
    && cd /usr/src/python \
    && gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
    && ./configure \
        --build="$gnuArch" \
        --enable-loadable-sqlite-extensions \
        --enable-shared \
        --with-system-expat \
        --with-system-ffi \
        --without-ensurepip \
    && make -j "$(nproc)" \
    && make install \
    && ldconfig \
    \
    && apt-mark auto '.*' > /dev/null \
    && apt-mark manual $savedAptMark \
    && find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
        | awk '/=>/ { print $(NF-1) }' \
        | sort -u \
        | xargs -r dpkg-query --search \
        | cut -d: -f1 \
        | sort -u \
        | xargs -r apt-mark manual \
    && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
    && rm -rf /var/lib/apt/lists/* \
    \
    && find /usr/local -depth \
        \( \
            \( -type d -a \( -name test -o -name tests \) \) \
            -o \
            \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
        \) -exec rm -rf '{}' + \
    && rm -rf /usr/src/python \
    \
    && python3 --version
RUN cd /usr/local/bin \
    && ln -s idle3 idle \
    && ln -s pydoc3 pydoc \
    && ln -s python3 python \
    && ln -s python3-config python-config
ENV PYTHON_PIP_VERSION 18.0
RUN set -ex; \
    \
    savedAptMark="$(apt-mark showmanual)"; \
    apt-get update; \
    apt-get install -y --no-install-recommends wget; \
    \
    wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
    \
    apt-mark auto '.*' > /dev/null; \
    [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
    apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
    rm -rf /var/lib/apt/lists/*; \
    \
    python get-pip.py \
        --disable-pip-version-check \
        --no-cache-dir \
        "pip==$PYTHON_PIP_VERSION" \
    ; \
    pip --version; \
    \
    find /usr/local -depth \
        \( \
            \( -type d -a \( -name test -o -name tests \) \) \
            -o \
            \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
        \) -exec rm -rf '{}' +; \
    rm -f get-pip.py    
RUN apt-get update && \
        apt-get install -y --no-install-recommends \
        build-essential \
        cmake \
        git \
        wget \
        unzip \
        yasm \
        pkg-config \
        libswscale-dev \
        libtbb2 \
        libtbb-dev \
        libjpeg-dev \
        libpng-dev \
        libtiff-dev \
        libavformat-dev \
        libpq-dev \
    && rm -rf /var/lib/apt/lists/*
RUN pip install numpy
WORKDIR /
ENV OPENCV_VERSION="3.4.2"
RUN wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip \
&& unzip ${OPENCV_VERSION}.zip \
&& mkdir /opencv-${OPENCV_VERSION}/cmake_binary \
&& cd /opencv-${OPENCV_VERSION}/cmake_binary \
&& cmake -DBUILD_TIFF=ON \
  -DBUILD_opencv_java=OFF \
  -DWITH_CUDA=OFF \
  -DWITH_OPENGL=ON \
  -DWITH_OPENCL=ON \
  -DWITH_IPP=ON \
  -DWITH_TBB=ON \
  -DWITH_EIGEN=ON \
  -DWITH_V4L=ON \
  -DBUILD_TESTS=OFF \
  -DBUILD_PERF_TESTS=OFF \
  -DCMAKE_BUILD_TYPE=RELEASE \
  -DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") \
  -DPYTHON_EXECUTABLE=$(which python) \
  -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
  -DPYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
  .. \
&& make install \
&& rm /${OPENCV_VERSION}.zip \
&& rm -r /opencv-${OPENCV_VERSION}  
CMD ["python"]

pip版本:

 root@68e4f88ab646:/# python -V
 Python 3.5.6

opencv版本:

 root@68e4f88ab646:/# pip -V
 pip 18.0 from /usr/local/lib/python3.5/site-packages/pip (python 3.5)

经测试可正常使用!