AWS Lambda: Unable to find libGL.so package while using moderngl / glcontext

277 Views Asked by At

I've tried a lot of solutions to similar issues but I've found that they're not quite specific enough or they're outdated (or maybe I'm not sharp enough!)

I'm packaging some Python code to run on AWS Lambda and it uses a number of packages including Numpy, Pillow, moderngl, and glcontext. I was able to package up the Python packages as layers, and could import everything, but keep running into this error:

"errorMessage": "libGL.so.1.2.0 not found in /lib, /usr/lib or LD_LIBRARY_PATH"

It was simply "libGL.so" until I changed the following line in my code from

moderngl.create_standalone_context()

to

moderngl.create_standalone_context(libgl='libGL.so.1.2.0')

based on this.

ALSO:

From the moderngl documentation I saw this line:

Please note that libGL.so is loaded dinamically by the backends.

I think that's my key to understanding what's going on here and how to tell Lambda to look for this lib, but nonetheless I haven't been able to make it work! I have tried updating environment variables in the function, packaging the layers with Docker, packaging a lib file with the code that contains the libGL.so file, and the list goes on.

I appreciate if anyone can help me out by pointing me to a solution or helping me understand what's going on! Thanks!

Full Exception:

{
  "errorMessage": "libGL.so.1.2.0 not found in /lib, /usr/lib or LD_LIBRARY_PATH",
  "errorType": "Exception",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 394, in lambda_handler\n    run(output_file)\n",
    "  File \"/var/task/lambda_function.py\", line 386, in run\n    CUSTOM_PACKAGE(path=\"sample\", dest=save_output_to, glasses_config=glasses_config, additional_info=additional_info)\n",
    "  File \"/var/task/lambda_function.py\", line 377, in CUSTOM_PACKAGE\n    fig = CUSTOM_PACKAGE2(dd, face=face , style=style, glasses_config=glasses_config, additional_info=additional_info, img_scale=img_scale,interpolation=interpolation, dpi=dpi, samples=samples, table_props=table_props, centers_move_y=centers_move_y)\n",
    "  File \"/var/task/lambda_function.py\", line 236, in CUSTOM_PACKAGE2\n    img_k,box_k = create_back_image(dd,xMinMax_k,img_scale=img_scale,samples=samples)\n",
    "  File \"/var/task/lambda_function.py\", line 48, in create_back_image\n    return draw_view(dd, eye, target, up, xMinMax, image_size, samples=samples)\n",
    "  File \"pltgl/pltgl.py\", line 85, in draw_view\n    return render_to_image(pnc, lookat_front, xMinMax, image_size, lightPos=eye, is_wireframe=is_wireframe,samples=samples)\n",
    "  File \"pltgl/pltgl.py\", line 29, in render_to_image\n    ctx = moderngl.create_standalone_context(libgl='libGL.so.1.2.0')\n",
    "  File \"/opt/python/lib/python3.8/site-packages/moderngl/context.py\", line 1664, in create_standalone_context\n    ctx.mglo, ctx.version_code = mgl.create_context(glversion=require, mode=mode, **settings)\n",
    "  File \"/opt/python/lib/python3.8/site-packages/glcontext/__init__.py\", line 83, in create\n    return x11.create_context(**kwargs)\n"
  ]
}
0

There are 0 best solutions below