PIL: ImportError: The _imaging extension was built for another version of pillow or PIL

This is only an installation issue.

First install pip on your system if it is not installed. It is available for Windows also.

Upgrade your numpy, pip/pillow, scipy:

pip install -U numpy
pip install -U pil/pillow
pip install -U scipy

The best option for Windows is to use anaconda.

I think pip is already installed in conda. This will resolve your system version issue.

In [1]: from PIL import Image

In [2]: import scipy.ndimage as spnd

In [3]: x = spnd.imread('ppuf100X91.gif')

In [4]: print x
[[255 255 255 ..., 255 255 255]
 [255 255 255 ..., 255 255 255]
 [255 255 255 ..., 255 255 255]
 ..., 
 [255 255 255 ..., 255 255 255]
 [255 255 255 ..., 255 255 255]
 [255 255 255 ..., 255 255 255]]

This is a problem in python 3.6 Edit file: C:\Anaconda\lib\site-packages\PIL\Image.py and change code:

if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
     raise ImportError("The _imaging extension was built for another "
                        " version of Pillow or PIL")

change that to:

if core.PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
     raise ImportError("The _imaging extension was built for another "
                        " version of Pillow or PIL")

This will solve the problem. Regards


Maybe one of your dependencies requires PIL and PIL ends up being installed after Pillow, causing conflicts in your site packages dir. I'm assuming you're seeing that error because the import statement is importing _imaging from a legitimate PIL installation and not a Pillow installation.

I've had trouble in the past with conflicting packages that require either PIL or Pillow. Pillow is, of course, the preferred package. I would take a look at the dependencies of your packages. If you can find one that depends on PIL, I would submit a pull request which changes the dependency to Pillow or maybe even create your own fork with that change. For my situation, forking was the option that I settled on since the project seemed to have had no activity on it for a long time.

Ultimately, you want to eliminate any dependencies on the PIL package (since it's no longer active) in favor of Pillow.