gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 20:58:37 27 4
gpt4 key购买 nike

我已经为此苦苦挣扎了几天,找不到在 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

最佳答案

在 Dockerfile 下方,使用 pip 默认安装 python3.5,并在 debian:jessie 基本镜像中安装 openCV 3.4.2。这将解决您的问题。

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"]

python 版本:

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

点子版本:

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

opencv 版本:

 root@68e4f88ab646:/# pkg-config --modversion opencv
3.4.2

经过测试并有效!!!

关于opencv - 如何在 docker (debian :jessie)) 上为 python3.5 安装 openCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52463690/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com