PIL:ImportError:_imaging扩展名是为枕头或PIL的另一个版本构建的
我得到错误:
---------------------------------------------------------------------------
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
每当我尝试使用PIL库时。我正在尝试加载和处理一堆.gif文件,而我现在正在尝试的操作如下:
from PIL import Image
通过以下方法尝试不同的方法:
import scipy.ndimage as spnd
os.chdir('C:\\WeatherSink\\data\\')
spnd.imread('2014-11-03-0645.gif')
失败:
---------------------------------------------------------------------------
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.
第一种方法指导我安装PIL的版本。我尝试模拟getattr(…),然后返回None。因此,它的功能还不足以令我感到惊讶。但是有人知道如何“修复”错误吗?
我在win7上运行,通过conda管理python2.7。我也尝试删除并重新安装软件包,但输出没有任何变化。
非常感谢帮助。
-
这只是一个安装问题。
如果尚未安装pip,请先在系统上安装它。它也可用于Windows。
升级您的numpy,pip /枕头,scipy:
pip install -U numpy pip install -U pil/pillow pip install -U scipy
Windows的最佳选择是使用anaconda。
我认为在conda中已经安装了pip。这样可以解决您的系统版本问题。
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]]