2

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 Answers2

1

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.

J_H
  • 17,926
  • 4
  • 24
  • 44
1

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"]
jellycsc
  • 10,904
  • 2
  • 15
  • 32
  • this was it, thank you. Worth noting that yum can only grab the http link, so you need to add ```sed -i "s/metalink=https/metalink=http/" /etc/yum.repos.d/epel.repo &&\``` after installing epel – ryanjackson Jul 05 '22 at 16:30
  • @ryanjackson Thanks for the note which can potentially help future readers! – jellycsc Jul 05 '22 at 18:45