Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

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

I get the error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-0f6709e38f49> in <module>()
----> 1 from PIL import Image

C:Anacondalibsite-packagesPILImage.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:Anacondalibsite-packagesscipy
dimageio.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...