'ImportError: Unable to find zbar shared library on Flask
Im trying to use pyzbar 0.1.4 on a Flask Server in Docker
The image was created by us, based in python 2.7 taken from alpine.
Install ZBar by
apk update
apk add zbar
Im getting the following error when running 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
Im trying to decode a QR image using that library
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
And 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
When pip install zbar ` pip install zbar Collecting zbar Downloading zbar-0.10.tar.bz2 ... zbarmodule.h:26:18: fatal error: zbar.h: No such file or directory
include
compilation terminated. error: command 'gcc' failed with exit status 1 `
Solution 1:[1]
In Ubuntu install zbar-tools
sudo apt-get install zbar-tools
Solution 2:[2]
In Ubuntu terminal simply run this command and this will install zbar in your global package
sudo apt-get install zbar-tools
Solution 3:[3]
I encountered the same issue (happy to have found this thread). Not sure if this has already been solved but this might help you or future devs.
As usual, it worked on my machine locally but couldn't get it to work in a container
What I tried initially:
- Building an image based on a Python3 image
What solved the issue:
- Build with FROM ubuntu:18.04
- Within Ubuntu I was able to install the zbar shared library. According to https://pypi.org/project/pyzbar/ we need
sudo apt-get install libzbar0 - Set
LC_ALL&LANGENV variables (not sure why, it was provided in an additional error) - Within requirements.txt downgrade
Pillow==8.4.0toPillow==6.2.2
My Dockerfile:
FROM ubuntu:18.04
RUN apt-get update -y
# Get's shared library for zbar
RUN apt-get install -y libzbar0
# Installs Python
RUN apt-get install -y python3-pip python3-dev build-essential
COPY . /app
WORKDIR /app
COPY requirements.txt .
RUN pip3 install -r requirements.txt
# Initially encountered an issue that indicated I had to set these ENVs
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
And requirements.txt
fastapi==0.67.0
Pillow==6.2.2
pyzbar==0.1.8
urllib3==1.26.7
uvicorn==0.12.2
Solution 4:[4]
I grea with the second commend on your post, but you might want to try to install the pyzbar dependency through pip.
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
Solution 5:[5]
You can use tf.keras.layers.Concatenatefrom Tensorflow Keras API to combine two models
# Concatenate last layer of model1 and model2
concat = tf.keras.layers.Concatenate()([dense_1, dense_2])
n_classes = 10
# output layer
output = tf.keras.layers.Dense(units=n_classes,
activation=tf.keras.activations.softmax)(concat)
Complete _model = tf.keras.Model(inputs=[input_1, input_2], outputs=[output])
complete _model.summary()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mise |
| Solution 2 | Neizvestnyj |
| Solution 3 | |
| Solution 4 | Ivonet |
| Solution 5 | TFer |
