I'm getting this error:
Traceback (most recent call last):
File "/var/task/barcode/writer.py", line 9, in <module>
import Image
ModuleNotFoundError: No module named 'Image'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
// etc etc
File "/var/task/barcode/base.py", line 80, in write
output = self.render(options, text)
File "/var/task/barcode/codex.py", line 255, in render
return super().render(options, text)
File "/var/task/barcode/base.py", line 100, in render
return self.writer.render(code)
File "/var/task/barcode/writer.py", line 269, in render
self._callbacks["paint_text"](xpos, ypos)
File "/var/task/barcode/writer.py", line 440, in _paint_text
font = ImageFont.truetype(self.font_path, font_size)
File "/var/task/PIL/ImageFont.py", line 791, in truetype
return freetype(font)
File "/var/task/PIL/ImageFont.py", line 788, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/var/task/PIL/ImageFont.py", line 198, in __init__
if core.HAVE_RAQM:
File "/var/task/PIL/_util.py", line 19, in __getattr__
raise self.ex
File "/var/task/PIL/ImageFont.py", line 48, in <module>
from . import _imagingft as core
ImportError: /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by Pillow.libs/libpng16-39c06ea1.so.16.40.0)
[ERROR] 2023-07-28T18:22:56.139Z d6ac4e4c-7517-45fc-a72e-47fe541f977a An error occurred running the application. Traceback (most recent call last): File "/var/task/barcode/writer.py", line 9, in <module> import Image ModuleNotFoundError: No module named 'Image' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/var/task/mangum/protocols/http.py", line 58, in run await app(self.scope, self.receive, self.send) File "/var/task/fastapi/applications.py", line 270, in __call__ await super().__call__(scope, receive, send) File "/var/task/starlette/applications.py", line 124, in __call__ await self.middleware_stack(scope, receive, send) File "/var/task/starlette/middleware/errors.py", line 184, in __call__ raise exc File "/var/task/starlette/middleware/errors.py", line 162, in __call__ await self.app(scope, receive, _send) File "/var/task/starlette/middleware/cors.py", line 84, in __call__ await self.app(scope, receive, send) File "/var/task/starlette/middleware/exceptions.py", line 79, in __call__ raise exc File "/var/task/starlette/middleware/exceptions.py", line 68, in __call__ await self.app(scope, receive, sender) File "/var/task/fastapi/middleware/asyncexitstack.py", line 21, in __call__ raise e File "/var/task/fastapi/middleware/asyncexitstack.py", line 18, in __call__ await self.app(scope, receive, send) File "/var/task/starlette/routing.py", line 706, in __call__ await route.handle(scope, receive, send) File "/var/task/starlette/routing.py", line 276, in handle await self.app(scope, receive, send) File "/var/task/starlette/routing.py", line 66, in app response = await func(request) File "/var/task/fastapi/routing.py", line 237, in app raw_response = await run_endpoint_function( File "/var/task/fastapi/routing.py", line 165, in run_endpoint_function return await run_in_threadpool(dependant.call, **values) File "/var/task/starlette/concurrency.py", line 41, in run_in_threadpool return await anyio.to_thread.run_sync(func, *args) File "/var/task/anyio/to_thread.py", line 33, in run_sync return await get_asynclib().run_sync_in_worker_thread( File "/var/task/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread return await future File "/var/task/anyio/_backends/_asyncio.py", line 807, in run result = context.run(func, *args) File "/var/task/app/app.py", line 210, in generate_pdf prescription_pdf(data, os.path.join('/tmp/', pdf_filename) ) File "/var/task/app/app.py", line 623, in prescription_pdf Code128(data['external_id'], writer=ImageWriter(format="PNG")).write(rv) File "/var/task/barcode/base.py", line 80, in write output = self.render(options, text) File "/var/task/barcode/codex.py", line 255, in render return super().render(options, text) File "/var/task/barcode/base.py", line 100, in render return self.writer.render(code) File "/var/task/barcode/writer.py", line 269, in render self._callbacks["paint_text"](xpos, ypos) File "/var/task/barcode/writer.py", line 440, in _paint_text font = ImageFont.truetype(self.font_path, font_size) File "/var/task/PIL/ImageFont.py", line 791, in truetype return freetype(font) File "/var/task/PIL/ImageFont.py", line 788, in freetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "/var/task/PIL/ImageFont.py", line 198, in __init__ if core.HAVE_RAQM: File "/var/task/PIL/_util.py", line 19, in __getattr__ raise self.ex File "/var/task/PIL/ImageFont.py", line 48, in <module> from . import _imagingft as core ImportError: /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by Pillow.libs/libpng16-39c06ea1.so.16.40.0)
When trying to execute
Code128(someNumber, writer=ImageWriter(format="PNG")).write(rv)
The problem (I think) is that zlib 1.2.9 doesn't exist in AWS lambda. I've already tried to add the layer from klayers that adds PIL but I'm getting the same error.
If I upgrade to Python3.9 or Python3.10 I get different (worse) errors. I'd like this to work with Python 3.8.