PIL 将不会导入 _imaging C 模块:“*** _imaging C 模块未安装”
PIL setup.py 构建的一些背景知识:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------
这是在 Ubuntu 9.04 安装上的。
我只需要 PIL 即可使 Django 上传各种图像(不同格式)并调整其大小。不幸的是,它目前无法处理 JPEG。执行 PIL 的 selftest.py 后,它想出了这个:
*** The _imaging C module is not installed
我尝试使用 python -v 解释器导入 Image 和 _imaging (两者都有效)...
>>> from PIL import Image
import PIL # directory PIL
# PIL/__init__.pyc matches PIL/__init__.py
import PIL # precompiled from PIL/__init__.pyc
# PIL/Image.pyc matches PIL/Image.py
import PIL.Image # precompiled from PIL/Image.pyc
[成功持续了很长一段时间]
>>> import _imaging
dlopen("/usr/local/lib/python2.6/dist-packages/PIL/_imaging.so", 2);
import _imaging # dynamically loaded from /usr/local/lib/python2.6/dist-packages/PIL/_imaging.so
所以使用 python 解释器时 _imaging 可用,但由于某种原因在其他情况下无法正确导入。
在过去的几个小时里,我一直在寻找这个问题的解决方案,但还没有找到任何解决方案。我错过了一些愚蠢而明显的事情吗?或者有什么想法可以解释为什么它不起作用吗?
提前致谢!
另外:我知道 http://effbot.org/zone/ pil-imaging-not-installed.htm 但这仅演示了错误并没有提供解决方案。
编辑: 我一直在窥探,看来导入 _imagingmath 是问题。我做了 python -vv selftest.py 来查看它在哪里损坏,这就是它发生的原因:
dlopen("/usr/local/lib/python2.6/dist-packages/PIL/_imagingmath.so", 2);
import _imagingmath # dynamically loaded from /usr/local/lib/python2.6/dist-packages/PIL/_imagingmath.so
*** The _imaging C module is not installed
# clear __builtin__._
[etc. etc. etc.]
A bit of background from the PIL setup.py build:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------
This is on an Ubuntu 9.04 installation.
I only need PIL to enable Django to upload and resize various images (of different formats). Unfortunately, it can't currently process JPEGs. After performing PIL's selftest.py, it came up with this:
*** The _imaging C module is not installed
I tried importing Image and _imaging using the python -v interpreter (which both worked)...
>>> from PIL import Image
import PIL # directory PIL
# PIL/__init__.pyc matches PIL/__init__.py
import PIL # precompiled from PIL/__init__.pyc
# PIL/Image.pyc matches PIL/Image.py
import PIL.Image # precompiled from PIL/Image.pyc
[continues successfully for quite a while]
>>> import _imaging
dlopen("/usr/local/lib/python2.6/dist-packages/PIL/_imaging.so", 2);
import _imaging # dynamically loaded from /usr/local/lib/python2.6/dist-packages/PIL/_imaging.so
So _imaging is available when using the python interpreter, but for some reason isn't being imported properly in other instances.
I've been looking for solutions to this problem for the last several hours and haven't come any closer to finding one. Am I missing something stupidly obvious? Or are there any ideas as to why it isn't working?
Thanks in advance!
Also: I am aware of http://effbot.org/zone/pil-imaging-not-installed.htm but that only demonstrates the error and provides no solution.
EDIT: I've been snooping around and it appears that importing _imagingmath is the problem. I did python -vv selftest.py to see where it was breaking, and this is how it happened:
dlopen("/usr/local/lib/python2.6/dist-packages/PIL/_imagingmath.so", 2);
import _imagingmath # dynamically loaded from /usr/local/lib/python2.6/dist-packages/PIL/_imagingmath.so
*** The _imaging C module is not installed
# clear __builtin__._
[etc. etc. etc.]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来我在安装PIL之前,并没有安装libjpeg。因此,我安装了 libjpeg-62 和 libjpeg62-dev,然后重新安装了 PIL。发生了同样的错误,
我在另一个网站上找到了一个潜在的解决方案,建议我从源代码强制重建 PIL:
这会抛出一些有关此错误的有趣信息(如果您也遇到此问题)。看来 gcc 没有正确编译各种文件(我有 gcc4.3.3),即以下内容:
(其他一切似乎都很好)
我对此做了一些研究,其他一些网站表明它是因为我用来构建 PIL 的 gcc 版本与我正在使用的构建 python.org Python 的版本不同。这很有道理。 这是另一个问题我发现这表明了这一点。
最后,我尝试了最后一次安装,但这次是从存储库安装,而不是我下载的 tar。这似乎已经解决了问题。
虽然我还没有完全回答原来的问题,但我找到了一个替代解决方案,并希望上述信息能够帮助其他人解决这种情况!
It seems that before I installed PIL, I didn't have libjpeg installed. I therefore installed libjpeg-62 and libjpeg62-dev, then reinstalled PIL. The same error occurred
I found a potential solution on another website suggesting that I force rebuild PIL from source:
This threw up a few interesting pieces of information about this error (if you're having this problem too). It seems that gcc isn't compiling various files properly (I have gcc4.3.3), namely the following:
(everything else seems fine)
I did a little research on this and some other websites suggest that it's because the version of gcc I'm using to build PIL is different from the version used to build the python.org Python I'm using. This makes quite a lot of sense. Here's the other question I found that suggests this.
Finally, I tried one last install, but this time from the repository as opposed to the tar I downloaded. This seems to have solved the problem.
Although I haven't entirely answered the original problem, I have found an alternative solution, and hope that the information above will be able to help anybody else in this situation!
我通过安装开发 libjpeg 解决了这个问题:
然后完全重新安装 PIL 模块。
(我使用的是虚拟环境,但它应该可以像标准环境一样运行 Python)
I fixed this by installing the development libjpeg:
Then re-install the PIL module altogether.
(I'm using a virtual environment, but it should work just as well running Python as standard)
您尚未安装 libjpeg 库。执行此操作:
并重新运行 PIL 安装。
You haven't installed the libjpeg library. Do this:
and re-run the PIL installation.