Emeraude
Emeraude

Reputation: 111

OSError: no library called "cairo" was found

I've been trying to figure out why I'm getting this error only when I'm running this in a docker container, but when I run my program locally, it works fine. I have looked at other posts on StackOverflow that had issues similar like this, but unfortunately they all seem to have problems running their programs locally, but in my case, I'm only having trouble in a container.

This project is for creating file(s) that can be used to print out property tag stickers (QR codes). The file(s) created are word documents with images embedded in them. The images are align to print on Avery Label Sheets.

OSError: no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': libcairo.so.2: cannot open shared object file: No such file or directory
cannot load library 'libcairo.2.dylib': libcairo.2.dylib: cannot open shared object file: No such file or directory
cannot load library 'libcairo-2.dll': libcairo-2.dll: cannot open shared object file: No such file or directory

This is what I have written in my requirements.txt. I am fairly certain that this should install all the dependencies that I need, but it just doesn't work in a docker container.

cairocffi==1.2.0
CairoSVG==2.5.2
cffi==1.14.5
cssselect2==0.4.1
defusedxml==0.7.1
lxml==4.6.3
Pillow==8.3.0
pycparser==2.20
PyQRCode==1.2.1
python-docx==0.8.11
PyYAML==5.4.1
svgwrite==1.4.1
tinycss2==1.1.0
webencodings==0.5.1

Upvotes: 2

Views: 3107

Answers (1)

Emeraude
Emeraude

Reputation: 111

The resolution to my problem is exactly as many people described; the libcairo.so2 library is not included in the python library. To add it into a docker container, you just had to edited the dockerfile like so...


FROM python:3.8-slim-buster

ENV PYTHONDONTWRITEBYTECODE=1

ENV PYTHONUNBUFFERED=1

# Install pip requirements
COPY requirements.txt .
RUN python3 -m pip install -r requirements.txt

RUN apt-get update -y
RUN apt-get install -y libcairo2

WORKDIR /app
COPY . /app


CMD ["python3", "insQr2.py"]

Upvotes: 6

Related Questions