Python PIL:ImportError:_imaging 扩展是为另一个版本的枕头或 PIL 构建的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26720968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PIL: ImportError: The _imaging extension was built for another version of pillow or PIL
提问by C.Buhl
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:
每当我尝试使用 PIL 库时。我正在尝试加载和处理一堆 .gif,而我现在正在尝试的是以下内容:
from PIL import Image
Trying a different approach, through scipy with:
通过 scipy 尝试不同的方法:
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?
第一种方法指导我安装 PIL 的版本。我尝试模拟 getattr(...),并返回 None。所以我对它的功能不足并不感到惊讶。但是有谁知道如何“修复”错误?
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.
我在win7上运行,通过conda管理python2.7。我也尝试删除并重新安装软件包,但输出没有任何变化。
Help is much appreciated.
非常感谢帮助。
采纳答案by aibotnet
This is only an installation issue.
这只是一个安装问题。
First install pip on your system if it is not installed. It is available for Windows also.
如果未安装 pip,请先在您的系统上安装 pip。它也适用于 Windows。
Upgrade your numpy, pip/pillow, scipy:
升级你的 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.
Windows 的最佳选择是使用anaconda。
I think pip is already installed in conda. This will resolve your system version issue.
我认为 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]]
回答by David Sanders
Maybe one of your dependencies requires PIL and PIL ends up being installed after Pillow, causing conflicts in your site packages dir. I'm assuming you're seeing that error because the import statement is importing _imagingfrom a legitimate PIL installation and not a Pillow installation.
也许您的依赖项之一需要 PIL,而 PIL 最终会在 Pillow 之后安装,从而导致您的站点包目录发生冲突。我假设您看到该错误是因为导入语句是_imaging从合法的 PIL 安装而不是 Pillow 安装导入的。
I've had trouble in the past with conflicting packages that require either PIL or Pillow. Pillow is, of course, the preferred package. I would take a look at the dependencies of your packages. If you can find one that depends on PIL, I would submit a pull request which changes the dependency to Pillow or maybe even create your own fork with that change. For my situation, forking was the option that I settled on since the project seemed to have had no activity on it for a long time.
过去我遇到过需要 PIL 或 Pillow 的冲突包的问题。枕头当然是首选的包装。我会看看你的包的依赖关系。如果你能找到一个依赖于 PIL 的,我会提交一个 pull request 来改变对 Pillow 的依赖,或者甚至可以用这个改变创建你自己的 fork。对于我的情况,分叉是我决定的选项,因为该项目似乎已经很长时间没有活动了。
Ultimately, you want to eliminate any dependencies on the PIL package (since it's no longer active) in favor of Pillow.
最终,您希望消除对 PIL 包的任何依赖(因为它不再处于活动状态)以支持 Pillow。
回答by Kiran Kantesariya
This problem is because of Python package of PIL/pillow is Up or Down version of your system and due to this question is generate in your system.
这个问题是因为 PIL/pillow 的 Python 包是您系统的 Up 或 Down 版本,并且由于这个问题是在您的系统中生成的。
Try to check this command:
尝试检查此命令:
sudo apt-get install python-PIL
Check this package is install or not. If it is installed than try to remove with the command:
检查这个包是否安装。如果已安装,请尝试使用以下命令删除:
sudo apt-get remove python-PIL
Check this will work to remove the PIL/pillow package is removed from your system.
检查这将有助于从您的系统中删除 PIL/pillow 包。
And finally this command will help you to solve this package problem:
最后这个命令将帮助你解决这个包问题:
sudo apt-get autoremove python-PIL
Then reinstall PIL/Pillow package:
然后重新安装 PIL/Pillow 包:
sudo apt-get install python-pil
This should help you solve the problem.
这应该可以帮助您解决问题。
回答by ibrahim
This is a problem in python 3.6
Edit file: C:\Anaconda\lib\site-packages\PIL\Image.pyand change code:
这是python 3.6 Edit file: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")
change that to:
将其更改为:
if core.PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
raise ImportError("The _imaging extension was built for another "
" version of Pillow or PIL")
This will solve the problem. Regards
这将解决问题。问候
回答by LeThang
i think acttually is the Virtual Environments you use when you run your code. many times computer will run Anaconda path instead of Python3. So you can try python or python 3 in command prompt before call your code. Example: python3 image.py. Or you can delete anaconda :D.
我认为实际上是您在运行代码时使用的虚拟环境。很多时候计算机将运行 Anaconda 路径而不是 Python3。因此,您可以在调用代码之前在命令提示符下尝试 python 或 python 3。示例:python3 image.py。或者你可以删除 anaconda :D。

