Failed to load CairoSVG in serverless program

Open
#402 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
flask, python
Domain
backend, cloud

Research direction

Start with drawsvg/raster.py and the full-feature installation guidance linked in the error, then review how the Flask app in the linked repository is deployed through Vercel. Determine whether the missing native libcairo library can be supplied by that deployment and document the supported dependency setup or limitation.

Written by the indexing model from the issue text.

Description

Hello, so im deploying my image api made in python flask with drawsvg, so the error is i can't install additonal packages in serverless ( or at least i don't know how), bellow are full logs, code is avalible here: https://github.com/Mankifg/LessApi , and this is my requirements.txt

drawsvg==2.3.0
Flask==2.2.2
Pillow==10.0.0

and I am deploing in vercel. If you nead any more info please let me know.

Thanks

Logs:

[ERROR]	2023-09-12T18:39:38.085Z	bf3817cd-34cc-4527-8b68-cfde954ddaad	Exception on /image [GET]
Traceback (most recent call last):
  File "/var/task/drawsvg/raster.py", line 9, in delay_import_cairo
    import cairosvg
  File "/var/task/cairosvg/__init__.py", line 26, in <module>
    from . import surface  # noqa isort:skip
  File "/var/task/cairosvg/surface.py", line 9, in <module>
    import cairocffi as cairo
  File "/var/task/cairocffi/__init__.py", line 47, in <module>
    cairo = dlopen(
  File "/var/task/cairocffi/__init__.py", line 44, in dlopen
    raise OSError(error_message)  # pragma: no cover
OSError: no library called "cairo-2" was found
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.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.so.2'
cannot load library 'libcairo.2.dylib': libcairo.2.dylib: cannot open shared object file: No such file or directory.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.2.dylib'
cannot load library 'libcairo-2.dll': libcairo-2.dll: cannot open shared object file: No such file or directory.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo-2.dll'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/task/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/var/task/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/task/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/task/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "./api/index.py", line 40, in get_image
    filename = generate_merged_image(t)
  File "/var/task/mergeimg.py", line 18, in generate_merged_image
    path = make_tile_and_save_it(dec)
  File "/var/task/geneate_image.py", line 141, in make_tile_and_save_it
    tile.save_png(path)
  File "/var/task/drawsvg/drawing.py", line 337, in save_png
    self.rasterize(to_file=fname, context=context)
  File "/var/task/drawsvg/drawing.py", line 340, in rasterize
    return raster.Raster.from_svg_to_file(
  File "/var/task/drawsvg/raster.py", line 56, in from_svg_to_file
    cairosvg = delay_import_cairo()
  File "/var/task/drawsvg/raster.py", line 11, in delay_import_cairo
    raise ImportError(
ImportError: Failed to load CairoSVG. drawSvg will be unable to output PNG or other raster image formats. See https://github.com/cduck/drawsvg#full-feature-install for more details.
Dominant language
Python
Stars
959
Forks
172
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Kozea/CairoSVG

All issues in Kozea/CairoSVG

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.