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

标签 python python-2.7 python-imaging-library

我得到错误:

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

通过 scipy 尝试不同的方法:

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,请先在系统上安装它。是available for Windows also .

升级你的 numpy、pip/pillow、scipy:

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

Windows 的最佳选择是使用 anaconda .

我认为 pip 已经安装在 conda 中。这将解决您的系统版本问题。

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

关于python - PIL : ImportError: The _imaging extension was built for another version of pillow or PIL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26720968/

相关文章:

python - 在 python 和 linux shell 中处理(二进制?)文件

python - numpy.memmap 到 Image.frombuffer - 不复制

python - 了解 Pillow 中的 histogram()

python - 如何删除值频率小于 5 的行? python , Pandas

javascript - AJAX 和 DJANGO 形式

python - 将 Universal Sentence Encoder 保存到 Tflite 或将其提供给 tensorflow api

python - 更改图形线条颜色

python - 将数组拆分为大致相等的 block

python - Pillow中bbox的参数是什么意思?

python-3.x - 如何在python中将png图像的目录转换为jpg