1

I'm having a very weird pillow version conflict on python 3.7.9 The only command I'm running on my Jupyter notebook cell is

import matplotlib.pyplot as plt

However, I'm getting the following error message:

ImportError: The _imaging extension was built for another version of Pillow or PIL:
Core version: "9.2.0"
Pillow version: 9.2.0

The Core version and Pillow version are matching, I have no clue where's the error. Maybe those quotation marks shouldn't be there? Every package I downloaded was always through Conda in a virtual env, not sure what the problem is/how could this have happened

lepsch
  • 8,927
  • 5
  • 24
  • 44
  • Welcome to SO! I'd recommend you upgrade `numpy`, `pil` or `pillow`, `scipy` packages. Just run `pip install -U ` for each of them. – lepsch Jul 14 '22 at 17:36

2 Answers2

2

I had the same problem with a fresh environment, with all packages at their newest version. It might be a bug. A quick fix is to modify the file which throws the error, which you can e.g. find at C:\user\miniconda3\envs\plotting\Lib\site-packages\PIL\Image.py.

At line 102, replace

    if __version__ != getattr(core, "PILLOW_VERSION", None):
    raise ImportError(
        "The _imaging extension was built for another version of Pillow or PIL:\n"
        f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
        f"Pillow version: {__version__}"
    )

with

    if __version__ != getattr(core, "PILLOW_VERSION", None).replace('"', ''):
    raise ImportError(
        "The _imaging extension was built for another version of Pillow or PIL:\n"
        f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
        f"Pillow version: {__version__}"
    )

By removing the quotations marks, the check will pass.

chrissi_gsa
  • 626
  • 5
  • 11
  • Thank you! I was thinking of just using a replace on the quotation marks, but was worried this might create wierd conflicts. I tried upvoting but I don't think I have enough SO points to vote ;-; – Lucas MiraB Jul 15 '22 at 18:07
  • See also [Pillow issue 6437: import PIL.Image double quotes for Core version: "9.2.0"](https://github.com/python-pillow/Pillow/issues/6437). Pay attention to [@Bartoli comment](https://github.com/python-pillow/Pillow/issues/6437#issuecomment-1189077129) – semmyk-research Aug 16 '23 at 05:35
0

If someone still needs to use pillow==9.2.0, such might want to note the following.

@chrissi_gsa workaround is viable. However, on the basis of the wise advice given by @hugo to the answer in a related SO, I'll recommend following the uninstall and installing approach (applicable version or an applicable patch). In essence, follow the same 'logical approach' proffer in this pillow issue #6862.

If one is using Notebook, kindly restart the kernel, otherwise you might be getting the pillow import error similar to the one below:

ImportError: The _imaging extension was built for another version of Pillow or PIL:
Core version: 10.0.0
Pillow version: 9.4.0
semmyk-research
  • 333
  • 1
  • 9