我得到错误:
---------------------------------------------------------------------------
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
每当我尝试使用PIL库时。我正在尝试加载和处理一堆.gif,现在我正在尝试的是:
from PIL import Image
尝试不同的方法,通过scipy with:
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:Anacondalibsite-packagesscipyndimageio.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/pallow,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 3.6中的一个问题编辑文件:C:Anacondalibsite-packagesPILImage.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")
这将解决问题。问候
也许您的某个依赖项需要PIL,而PIL最终在Pillow之后安装,导致您的站点包目录发生冲突。我假设您看到了这个错误,因为import语句是从合法的PIL安装而不是Pillow安装导入_imaging
。
我过去遇到过需要PIL或Pillow的相互矛盾的包裹的问题。枕头当然是首选的包装。我会看看你的包的依赖关系。如果你能找到一个依赖PIL的,我会提交一个pull请求,将依赖关系更改为Pillow,甚至可以用这个更改创建你自己的fork。就我的情况而言,分叉是我决定的选项,因为这个项目似乎已经很长时间没有活动了。
最终,您希望消除对PIL软件包的任何依赖(因为它不再是活动的),以支持Pillow。
这个问题是因为PIL/pillow的Python包是您系统的Up或Down版本,并且由于这个问题而在您的系统中生成。
尝试检查此命令:
sudo apt-get install python-PIL
检查此程序包是否已安装。如果已安装,则尝试使用以下命令删除:
sudo apt-get remove python-PIL
检查此项是否能将PIL/枕头套装从系统中移除。
最后,这个命令将帮助您解决这个包问题:
sudo apt-get autoremove python-PIL
然后重新安装PIL/枕头套装:
sudo apt-get install python-pil
这应该能帮助你解决问题。
我认为实际是您在运行代码时使用的虚拟环境。很多时候,计算机会运行Anaconda路径而不是Python3。因此,在调用代码之前,您可以在命令提示符下尝试python或python 3。示例:python3 image.py。或者你可以删除anaconda:D。
重新安装程序包,上面提到的错误可能也会对您有所帮助。当pip install -U
不工作时,它在我的电脑上工作。