python - 在Docker Image中安装python3.5的zbarlight python包

标签 python dockerfile python-3.5

我想在 Docker 镜像中安装带有 Python 3.5 的 zbarlight python 包。

Dockerfile如下

FROM python:3.5
WORKDIR /app
ADD . /app
RUN pip3 install -r requirements.txt
EXPOSE 80
CMD ["python", "main.py"]

Requirements.txt文件如下

Flask==0.12.2
google-cloud==0.27.0
gunicorn==19.7.1
Pillow==4.2.1
numpy==1.13.1
Werkzeug==0.12.2
oauth2client==3.0.0
zbarlight==1.2

错误如下。

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python3.5m -c src/zbarlight/_zbarlight.c -o build/temp.linux-x86_64-3.5/src/zbarlight/_zbarlight.o -std=c99
src/zbarlight/_zbarlight.c:3:18: fatal error: zbar.h: No such file or directory
 #include <zbar.h>
                  ^
compilation terminated.
error: command 'gcc' failed with exit status 1

然后我通过本地安装了libzbar-dev

sudo apt-get install libzbar-dev

然后在本地尝试以下命令。

dpkg -L libzbar-dev

上述命令的响应

/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libzbar-dev
/usr/share/doc/libzbar-dev/copyright
/usr/include
/usr/include/zbar.h
/usr/include/zbar
/usr/include/zbar/Image.h
/usr/include/zbar/Processor.h
/usr/include/zbar/Symbol.h
/usr/include/zbar/Decoder.h
/usr/include/zbar/Scanner.h
/usr/include/zbar/Exception.h
/usr/include/zbar/Video.h
/usr/include/zbar/Window.h
/usr/include/zbar/ImageScanner.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libzbar.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/zbar.pc
/usr/share/doc/libzbar-dev/changelog.Debian.gz
/usr/lib/x86_64-linux-gnu/libzbar.so

第二条命令

ls -l /usr/include/zbar.h

上述命令的响应。

-rw-r--r-- 1 root root 47339 Jan 28  2016 /usr/include/zbar.h

然后在 Dockerfile 中添加前两行。

FROM ubuntu:16.04
RUN apt-get update; apt-get install -yV libzbar0 libzbar-dev; dpkg -L libzbar-dev; ls -l /usr/include/zbar.h; apt-get update
FROM python:3.5
WORKDIR /app
ADD . /app
RUN pip install -r requirements.txt
EXPOSE 80
CMD ["python", "main.py"]

构建 Docker 镜像时的一些重要屏幕截图。

Responses : dpkg -L libzbar-dev & ls -l /usr/include/zbar.h

The Final Error

最佳答案

我更改了我的 Dockerfile,如下所示。

FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y zbar-tools libzbar-dev python-zbar
RUN dpkg -L libzbar-dev; ls -l /usr/include/zbar.h
RUN apt-get update
RUN apt-get install -y python3.5
WORKDIR /app
ADD . /app
RUN rm /usr/bin/python
RUN ln -s /usr/bin/python3.5 /usr/bin/python
RUN apt-get install -y python3-pip
RUN apt-get install -y python3-venv
RUN pip3 install -r requirements.txt
EXPOSE 80
CMD ["python", "main.py"]

当我改变主意使用 Python 3.5 的官方 Docker 镜像时,我将 Python 作为软件包安装。 并更改了默认的python版本(修改了软链接(soft link))。

关于python - 在Docker Image中安装python3.5的zbarlight python包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46461838/

相关文章:

python - 是什么导致了一个简单的函数调用导致此 KeyError?

python - 哪些 Scipy 模块实际上调用了 Numpy 模块?

python - 简单的python日志记录配置中的重复输出

python - 从 Pandas DataFrame 中选择一列中具有相同值但另一列中具有不同值的行

docker - 使用dockerfile运行mkdir命令

node.js - 在一个 docker 镜像中运行两个 nodejs 应用程序

docker - 部署角度后始终响应nginx索引

python - "try: input() except KeyboardInterrupt:"有解决方法吗

progress-bar - 使用tqdm的asyncio aiohttp进度栏

python 3 : Perfect Alphabetical Order