Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I get the error:

--------------------------------------------------------------------------- ImportError                               Traceback (most recent call last) <ipython-input-4-0f6709e38f49> in <module>() ----> 1 from PIL import Image  C:\Anaconda\lib\site-packages\PIL\Image.py in <module>()      61     from PIL import _imaging as core      62     if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None): ---> 63         raise ImportError("The _imaging extension was built for another "      64                           " version of Pillow or PIL")      65   ImportError: The _imaging extension was built for another  version of Pillow or PIL 

Whenever I try to use the PIL library. I'm trying to load and work on a bunch of .gif's, and what I'm trying now, is the following:

from PIL import Image 

Trying a different approach, through scipy with:

import scipy.ndimage as spnd os.chdir('C:\\WeatherSink\\data\\') spnd.imread('2014-11-03-0645.gif') 

Fails with:

--------------------------------------------------------------------------- ImportError                               Traceback (most recent call last) <ipython-input-3-23c383b79646> in <module>()       1 os.chdir('C:\\WeatherSink\\data\\') ----> 2 spnd.imread('2014-11-03-0645.gif')  C:\Anaconda\lib\site-packages\scipy\ndimage\io.pyc in imread(fname, flatten, mode)      36         from PIL import Image      37     except ImportError: ---> 38         raise ImportError("Could not import the Python Imaging Library (PIL)"      39                           " required to load image files.  Please refer to"      40                           " http://pypi.python.org/pypi/PIL/ for installation"  ImportError: Could not import the Python Imaging Library (PIL) required to load image files.  Please refer to http://pypi.python.org/pypi/PIL/ for installation instructions. 

The first approach guides me towards the versions of PIL installed. I try emulating the getattr(...), and that returns None. So I'm not surprised that it's less than functioning. But does anyone know how to 'fix' the errors?

I'm running on win7, managing python2.7 through conda. I've tried to remove and re-install the packages as well, without any change in the output.

Help is much appreciated.

like image 288
C.Buhl Avatar asked Nov 03 '14 18:11

C.Buhl


People also ask

How do I import a picture into PIL?

To load the image, we simply import the image module from the pillow and call the Image. open(), passing the image filename. Instead of calling the Pillow module, we will call the PIL module as to make it backward compatible with an older module called Python Imaging Library (PIL).


1 Answers

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]] 
like image 88
aibotnet Avatar answered Oct 14 '22 10:10

aibotnet