Kozea / cairocffi

CFFI-based cairo bindings for Python.
https://doc.courtbouillon.org/cairocffi
BSD 3-Clause "New" or "Revised" License
208 stars 54 forks source link

AWS Beanstalk no library called "libcairo-2" was found #193

Closed vlntsolo closed 1 year ago

vlntsolo commented 3 years ago

Hi, I've got weasyprint package nicely running on Ubuntu, but after deploying to the AWS Beanstalk (Amazon Linux 2) cairocffi can't find libraries.

Jul 12 11:53:43 ip-172-31-10-28 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/cairocffi/__init__.py", line 50, in <module>
Jul 12 11:53:43 ip-172-31-10-28 web: ('libcairo.so.2', 'libcairo.2.dylib', 'libcairo-2.dll'))
Jul 12 11:53:43 ip-172-31-10-28 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/cairocffi/__init__.py", line 45, in dlopen
Jul 12 11:53:43 ip-172-31-10-28 web: raise OSError(error_message)  # pragma: no cover
Jul 12 11:53:43 ip-172-31-10-28 web: OSError: no library called "cairo" was found
Jul 12 11:53:43 ip-172-31-10-28 web: no library called "libcairo-2" was found
Jul 12 11:53:43 ip-172-31-10-28 web: cannot load library 'libcairo.so.2': libcairo.so.2: cannot open shared object file: No such file or directory
Jul 12 11:53:43 ip-172-31-10-28 web: cannot load library 'libcairo.2.dylib': libcairo.2.dylib: cannot open shared object file: No such file or directory
Jul 12 11:53:43 ip-172-31-10-28 web: cannot load library 'libcairo-2.dll': libcairo-2.dll: cannot open shared object file: No such file or directory

Looking for those three files within terminal I've found only the libcairo.so.2 at /usr/lib64/libcairo.so.2

Installation with pip doesn't return any errors. python -m pip --no-cache-dir install cairocffi. So it seems to be installed smoothly. My first thought was that python virtual environment doesn't contain PKG_CONFIG_PATH variable. But I'm not sure what to put there.

liZe commented 3 years ago

Hello!

If /usr/lib64/libcairo.so.2 exists, then Python should be able to find it with dlopen (that’s what Python’s ffi library uses). You can type man dlopen to know how libraries are found. Setting LD_LIBRARY_PATH is probably the easiest way.

aeveltstra commented 1 year ago

Hello! The same issue happens when running cairoffi in a virtualenv created by pipenv, when the cairo libraries are installed using Fink. Fink on MacOs installs its libraries outside of the normal path, in /sw/lib. That path is not checked by dlopen, nor by ctypes.util.find_library(). The solution is the same: add libcairo's folder to LD_LIBRARY_PATH.

liZe commented 1 year ago

@aeveltstra Did you try to use Fink’s Python to create the virtual environment with pipenv? I don’t know how Fink works, but other tools like Homebrew tweak their Python version to make it search in the folders where its libraries are installed.

Otherwise, Python can’t magically find the libraries that are installed in non-standard paths, and setting LD_LIBRARY_PATH is the easiest solution.

aeveltstra commented 1 year ago

@aeveltstra Did you try to use Fink’s Python to create the virtual environment with pipenv?

I'll make sure to check that!