Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load CairoSVG in serverless program #402

Open
Mankifg opened this issue Sep 12, 2023 · 8 comments
Open

Failed to load CairoSVG in serverless program #402

Mankifg opened this issue Sep 12, 2023 · 8 comments

Comments

@Mankifg
Copy link

Mankifg commented Sep 12, 2023

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.
@liZe
Copy link
Member

liZe commented Sep 12, 2023

Hi!

Your problem is probably caused by missing system libraries. CairoSVG relies on libraries that can’t be installed using the Python package manager, so you have to install them. On Vercel, you should be able to do this following https://vercel.com/docs/deployments/build-image#installing-additional-packages

The package you need to install is Cairo.

@Mankifg
Copy link
Author

Mankifg commented Sep 15, 2023

hi, a looked a bit into logs and i tried using

yum install cairo -y

and

amazon-linux-extras install cairo

but it didn't worked. The logs are same. Do you know the command to fix it?

@liZe
Copy link
Member

liZe commented Sep 16, 2023

Could you please share amazon-linux-extras install cairo logs?

@Mankifg
Copy link
Author

Mankifg commented Sep 16, 2023

image
this is error logs:

GET]

/image

Time
September 16 10:29:07.35 GMT+02:00
Request Path
less-p271pg1uc-mankifg.vercel.app/image
Status Code
500
Host
less-p271pg1uc-mankifg.vercel.app
Request ID
g8lkq-1694852947343-cd87dba08c51
Request User Agent
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Level
Error

Environment
preview
Cache
MISS
Type
Serverless Function

Function
/api/index.py
Location
Washington, D.C., USA (iad1)
Runtime
Python 3.9

Execution Duration / Limit
798ms / 10s
Memory Used / Limit
89 MB / 1024 MB
1,1,1,1,1,1,1,1,1
000000000001
[ERROR]	2023-09-16T08:29:08.202Z	85c1d036-56fb-486f-a00d-a36f2a0d9ccc	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.

and i found there logs:

Running build in Washington, D.C., USA (East) – iad1 (Hive)
--
10:27:07.405 | Cloning github.com/Mankifg/LessApi (Branch: main, Commit: 21ca055)
10:27:07.723 | Cloning completed: 317.533ms
10:27:07.890 | Restored build cache
10:27:07.957 | Running "vercel build"
10:27:08.498 | Vercel CLI 32.2.4
10:27:08.660 | WARN! Due to `builds` existing in your configuration file, the Build and Development Settings defined in your Project Settings will not apply. Learn More: https://vercel.link/unused-build-settings
10:27:08.686 | Installing required dependencies...
10:27:33.746 | Build Completed in /vercel/output [25s]
10:27:34.150 | Deploying outputs...
10:27:49.691 | Deployment completed
10:27:50.259 | Uploading build cache [29.00 B]...
10:27:50.637 | Build cache uploaded: 377.315ms

@liZe
Copy link
Member

liZe commented Sep 16, 2023

Then I’m sorry, but I won’t be able to help you, I don’t know Vercel at all, and it’s definitely a problem with Vercel. If Cairo was installed, you wouldn’t have this error.

WARN! Due to builds existing in your configuration file, the Build and Development Settings defined in your Project Settings will not apply. Learn More: https://vercel.link/unused-build-settings

Looks like the commands you put in your dashbord are not applied. You should ask the Vercel community, there’s nothing we can do here for you :/.

@Mankifg
Copy link
Author

Mankifg commented Sep 16, 2023

well now i remove someting and i get error that cairo is not found

Vercel CLI 32.2.4
2023-09-16T09:06:20.834Z  Running "install" command: `amazon-linux-extras install cairo`...
2023-09-16T09:06:22.652Z  Topic cairo is not found.
2023-09-16T09:06:22.671Z  Error: Command "amazon-linux-extras install cairo" exited with 4

@Mankifg
Copy link
Author

Mankifg commented Sep 18, 2023

Could you please share amazon-linux-extras install cairo logs?

Vercel CLI 32.2.4
2023-09-16T09:06:20.834Z Running "install" command: amazon-linux-extras install cairo...
2023-09-16T09:06:22.652Z Topic cairo is not found.
2023-09-16T09:06:22.671Z Error: Command "amazon-linux-extras install cairo" exited with 4

here are logs

@liZe
Copy link
Member

liZe commented Sep 19, 2023

@Mankifg Then you have to ask on Vercel forums how to install cairo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants