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

通过 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。我也尝试删除并重新安装软件包,但输出没有任何变化。

非常感谢您的帮助。

原文由 C.Buhl 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.8k
2 个回答

这只是一个安装问题。

如果未安装 pip,请先在您的系统上安装它。它也 适用于 Windows

升级你的 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]]

原文由 aibotnet 发布,翻译遵循 CC BY-SA 4.0 许可协议

这是 python 3.6 中的一个问题 编辑文件: C:\Anaconda\lib\site-packages\PIL\Image.py 并更改代码:

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

将其更改为:

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

这将解决问题。问候

原文由 ibrahim 发布,翻译遵循 CC BY-SA 4.0 许可协议

推荐问题