3

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.

  • 4
    If I remember right, pil went through a weird update and changed the capitalization at some point. Old tutorials will probably use the old capitalization. Don't have enough time to make this a full answer right now – Pro Q Jan 24 '22 at 22:17
  • 3
    interesting, i installed pil 9.0.0 just now and can only use `import PIL`, not `import pil` – jkr Jan 24 '22 at 22:22
  • 3
    @ProQ where did you get that information? Pillow is still imported via `PIL` – Iain Shelvington Jan 24 '22 at 22:24
  • 3
    The Pillow version of the PIL has used uppercase `PIL` for as long as I can remember (i.e. since its beginning) — probably for historical reasons as it's always shrived to be compatible with the original. Anyway, it sounds like you gotten a hold of some sort of customized version. – martineau Jan 24 '22 at 22:46
  • @martineau I'm thinking my custom installation of d3dshot somehow installed a custom version of Pillow. I'll try uninstalling and reinstalling all that stuff and see if it helps. Thanks – Julian Fritz Jan 25 '22 at 23:36
  • I've encountered this same issue with a previously working install of Pytorch... but my conda environment hadn't been updated since August last year. The thing that finally fixed it was re-installing the entire virtual environment - reinstalling just the package didn't help. – LSgeo Jan 28 '22 at 06:03

1 Answers1

4

Several references suggest capitalizing Pillow when installing it via pip, including the official documentation, PyPi, 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.

LSgeo
  • 321
  • 3
  • 6