python qrcode

Hello, I am getting a weird bug, where it is looking for PIL from QRcode. But I am not importing PIL.
2, in

2025-05-18T01:50:18.932 app[91853199f0e938] iad [info] from PIL import Image, ImageDraw

2025-05-18T01:50:18.932 app[91853199f0e938] iad [info] ModuleNotFoundError: No module named ‘PIL’
I simply used qrcode.save to save the Qrcode as an image and used BytesIO() as the buffer. It works on my computer fine. I am not sure why it’s not on fly.io.

Even if you didn’t explicitly declare or import PIL in your code, it’s likely your qrcode-generating library uses PIL as a dependency (PIL is a generic image processing library).

What’s likely happening is that on your local system you have PIL installed systemwide, so it works’; but the Docker image you’re deploying to Fly does not include PIL as a dependency and so it fails. (which is a bit odd because your qr library should declare PIL as a dependency so it should be installed when you install the qr code library in the Docker image).

What you can do to check this, is build and run the Docker image locally. You should have a Dockerfile, so try docker build . --tag my-app and then docker run my-app (you also need to map some ports to access the app, this is out of scope for my reply, please check some online documentation on how to do this). You’ll likely see it fail the same way - this is not a Fly platform issue.

There are a few ways you can ensure the PIL dependency is added to your image, this depends on what your Dockerfile and Python dependency file (requirements.txt, pyproject.toml) look like so I can’t give more concrete advice but TL;DR ensure PIL is installed . Note the package name for PIL is “pillow” (pillow · PyPI).

  • Daniel

Thank you for your input. I will look into the documentation.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.