Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "from PIL import Image" not work, but "from pil import Image" does? (lowercase pil)

I've come across this strange error with Pillow, where the import name PIL needs to be all lowercase instead of all uppercase, but I've never seen pil used lowercase anywhere. This means that all the python packages and files that I use that import PIL don't work and throw a ModuleNotFoundError: No module named 'PIL'. However when change "PIL" to "pil", the import works.

Pillow version = 9.0.0
Python version = 3.9.1

I came across this error after trying to install d3dshot package. Installing d3dshot using pip threw an error about a missing zlib dependency for Pillow, and I followed this answer to successfully install d3dshot. After that, I started encountering this PIL error.

like image 406
Julian Fritz Avatar asked Sep 13 '25 19:09

Julian Fritz


1 Answers

Several references suggest capitalizing Pillow when installing it via pip, including the official documentation, and a lot of related stack overflow posts e.g. 1.

I'd suggest trying Pillow = ">=7.1.2" with a capital P in the pyproject.toml.

For anyone else with this issue, uninstalling pillow and ensuring it is installed using Pillow might resolve the issue.

like image 192
LSgeo Avatar answered Sep 17 '25 13:09

LSgeo