ImportError:无法在Flask上找到zbar共享库

时间:2018-02-14 17:24:57

标签: python python-2.7 docker zbar

我试图在Docker的Flask服务器上使用pyzbar 0.1.4

图像由我们创建,基于从高山中获取的python 2.7。

安装ZBar
apk update
apk add zbar

运行dockerfile时出现以下错误 File "/usr/lib/python2.7/site-packages/pyzbar/pyzbar.py", line 8, in <module> from .wrapper import ( File "/usr/lib/python2.7/site-packages/pyzbar/wrapper.py", line 166, in <module> c_uint_p, # minor File "/usr/lib/python2.7/site-packages/pyzbar/wrapper.py", line 159, in zbar_function return prototype((fname, load_libzbar())) File "/usr/lib/python2.7/site-packages/pyzbar/wrapper.py", line 135, in load_libzbar raise ImportError('Unable to find zbar shared library') ImportError: Unable to find zbar shared library

我试图使用该库解码QR图像

Dockerfile

FROM buffetcontainerimages.azurecr.io/base/buffetcloud-python:0.1
RUN pip install --upgrade pip setuptools wheel
COPY wheeldir /opt/app/wheeldir
COPY *requirements.txt /opt/app/src/
RUN pip install --use-wheel --no-index --find-links=/opt/app/wheeldir \
-r /opt/app/src/requirements.txt
RUN pip install --use-wheel --no-index --find-links=/opt/app/wheeldir \
-r /opt/app/src/test-requirements.txt
COPY . /opt/app/src/
WORKDIR /opt/app/src
RUN python setup.py install
EXPOSE 5000
CMD dronedemo

和requirements.txt

requests>=2.18.4
flask>=0.12.2
mechanize>=0.3.6
regex>=2.4.136
PyPDF2>=1.26.0
bs4>=4.5.3
pyzbar>=0.1.4
openpyxl>=2.5.0
selenium>=3.9.0
matplotlib>=2.1.2

当pip安装zbar时 ` 点击安装zbar 收集zbar 正在下载zbar-0.10.tar.bz2 ... zbarmodule.h:26:18:致命错误:zbar.h:没有这样的文件或目录

包括

编译终止。 错误:命令'gcc'失败,退出状态为1 `

4 个答案:

答案 0 :(得分:3)

一个简单的测试,看起来不错。

FROM python:2.7
RUN apt-get update && \
    apt-get install -y build-essential libzbar-dev && \
    pip install zbar

我试过alpine ..但是zbar lib只能在边缘分支中使用 - 尝试让它工作比实际值更麻烦。

PS。小心不在docker repo中的图像。 - 不知道这是你的图像

工作示例:

$ docker build -t yourimagenamehere .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM python:2.7
 ---> 9e92c8430ba0
... trunc...
Successfully built d951cd32ea74
Successfully tagged yourimagenamehere:latest
$ docker run -it --rm yourimagenamehere 
Python 2.7.14 (default, Dec 12 2017, 16:55:09) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zbar
>>> 

答案 1 :(得分:1)

在Ubuntu中安装zbar-tools

sudo apt-get install zbar-tools

答案 2 :(得分:0)

我对你的帖子提出了第二个建议,但你可能想尝试通过pip安装pyzbar依赖。

FROM buffetcontainerimages.azurecr.io/base/buffetcloud-python:0.1
RUN pip install --upgrade pip setuptools wheel pyzbar
COPY wheeldir /opt/app/wheeldir
COPY *requirements.txt /opt/app/src/
RUN pip install --use-wheel --no-index --find-links=/opt/app/wheeldir \
-r /opt/app/src/requirements.txt
RUN pip install --use-wheel --no-index --find-links=/opt/app/wheeldir \
-r /opt/app/src/test-requirements.txt
RUN pip install -y pyzbar
COPY . /opt/app/src/
WORKDIR /opt/app/src
RUN python setup.py install
EXPOSE 5000
CMD dronedemo

答案 3 :(得分:0)

Ubuntu 终端中只需运行此命令,这将在您的全局包中安装 zbar

sudo apt-get install zbar-tools