No package zbar available in lambda layer

1k views Asked by At

trying to create a layer for my lambda function which uses the pyzbar library, which requires the zbar shared library as dependency, to be downloaded separately, and can't be installed with pip. My Dockerfile looks like this:

FROM public.ecr.aws/lambda/python:3.8

COPY requirements.txt .
COPY lambda_function.py .

RUN pip install --upgrade pip &&\
    pip install -r requirements.txt &&\
    yum makecache &&\
    yum -y install zbar

CMD [ "lambda_function.lambda_handler"]

and my requirements.txt like this

opencv-python-headless
pyzbar
pyzbar[scripts]

I'm getting the error

No package zbar available

I'm getting the same error when I replace "zbar" with a number of other package names, e.g. libzbar0, libzbar-dev, zbar-tools, etc

2

There are 2 answers

2
jellycsc On BEST ANSWER

zbar is not included in the default amazon linux repo, so you need to add the epel repo.

FROM public.ecr.aws/lambda/python:3.8

COPY requirements.txt .
COPY lambda_function.py .

RUN pip install --upgrade pip &&\
    pip install -r requirements.txt &&\
    yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm &&\
    yum makecache &&\
    yum -y install zbar

CMD [ "lambda_function.lambda_handler"]
0
J_H On

You tried to install
https://pypi.org/project/pyzbar/ with pip, rather than
https://anaconda.org/conda-forge/pyzbar with conda.

Pip is very good at quickly solving pure-python installs. Conda solves a different class of problems. Here, you wish to incorporate binaries from zbar into your project, and you have expressed some frustration with the pip approach.

Using a conda environment.yml file would be the natural way to express your requirements. It will deal with obtaining platform-appropriate binaries for you, so you don't have to sweat the details.