gpt4 book ai didi

python - 在 Docker 容器中安装 OpenCV

转载 作者:IT老高 更新时间:2023-10-28 12:40:56 49 4
gpt4 key购买 nike

我正在尝试 Dockerise 一个依赖于 OpenCV 的 Python 应用程序。我尝试了几种不同的方法,但是当我尝试运行应用程序时,我不断收到... ImportError: No module named cv2

这是我当前的 Dockerfile。

FROM python:2.7

MAINTAINER Ewan Valentine <ewan@theladbible.com>

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Various Python and C/build deps
RUN apt-get update && apt-get install -y \
wget \
build-essential \
cmake \
git \
pkg-config \
python-dev \
python-opencv \
libopencv-dev \
libav-tools \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libjasper-dev \
libgtk2.0-dev \
python-numpy \
python-pycurl \
libatlas-base-dev \
gfortran \
webp \
python-opencv

# Install Open CV - Warning, this takes absolutely forever
RUN cd ~ && git clone https://github.com/Itseez/opencv.git && \
cd opencv && \
git checkout 3.0.0 && \
cd ~ && git clone https://github.com/Itseez/opencv_contrib.git && \
cd opencv_contrib && \
git checkout 3.0.0 && \
cd ~/opencv && mkdir -p 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=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=OFF .. && \
make -j4 && \
make install && \
ldconfig

COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt

COPY . /usr/src/app

还有我的 requirements.txt 文件

Flask==0.8
gunicorn==0.14.2
requests==0.11.1
bs4==0.0.1
nltk==3.2.1
pymysql==0.7.2
xlsxwriter==0.8.5
numpy==1.11
Pillow==3.2.0
cv2==1.0
pytesseract==0.1

最佳答案

使用稍微不同的设置进行了修复

FROM python:2.7

MAINTAINER Ewan Valentine <ewan@theladbible.com>

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Various Python and C/build deps
RUN apt-get update && apt-get install -y \
wget \
build-essential \
cmake \
git \
unzip \
pkg-config \
python-dev \
python-opencv \
libopencv-dev \
libav-tools \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libjasper-dev \
libgtk2.0-dev \
python-numpy \
python-pycurl \
libatlas-base-dev \
gfortran \
webp \
python-opencv \
qt5-default \
libvtk6-dev \
zlib1g-dev

# Install Open CV - Warning, this takes absolutely forever
RUN mkdir -p ~/opencv cd ~/opencv && \
wget https://github.com/opencv/opencv/archive/3.0.0.zip && \
unzip 3.0.0.zip && \
rm 3.0.0.zip && \
mv opencv-3.0.0 OpenCV && \
cd OpenCV && \
mkdir build && \
cd build && \
cmake \
-DWITH_QT=ON \
-DWITH_OPENGL=ON \
-DFORCE_VTK=ON \
-DWITH_TBB=ON \
-DWITH_GDAL=ON \
-DWITH_XINE=ON \
-DBUILD_EXAMPLES=ON .. && \
make -j4 && \
make install && \
ldconfig

COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt

COPY . /usr/src/app

关于python - 在 Docker 容器中安装 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36862589/

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