gpt4 book ai didi

python - PIL 不会导入_imaging C 模块 : "*** The _imaging C module is not installed"

转载 作者:太空狗 更新时间:2023-10-30 02:23:25 24 4
gpt4 key购买 nike

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

所以 _imaging 在使用 python 解释器时可用,但由于某些原因在其他情况下无法正确导入。

在过去的几个小时里,我一直在寻找解决这个问题的方法,但一直没有找到。我错过了一些愚蠢明显的东西吗?或者对于为什么它不起作用有任何想法?

提前致谢!

另外:我知道 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.]

最佳答案

看来我在安装PIL之前,并没有安装libjpeg。因此,我安装了 libjpeg-62 和 libjpeg62-dev,然后重新安装了 PIL。出现同样的错误

*** The _imaging C module is not installed

我在另一个网站上找到了一个潜在的解决方案,建议我从源代码强制重建 PIL:

sudo python setup.py build_ext -f

这引发了一些关于此错误的有趣信息(如果您也遇到此问题)。似乎 gcc 没有正确编译各种文件(我有 gcc4.3.3),即以下内容:

_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
libImaging/Quant.c: In function 'rehash_collide':
libImaging/Quant.c:154: warning: cast to pointer from integer of different size

(其他一切似乎都很好)

我对此做了一些研究,其他一些网站表明这是因为我用来构建 PIL 的 gcc 版本与用来构建我正在使用的 python.org Python 的版本不同。这很有道理。 Here's the other question I found that suggests this .

最后,我尝试了最后一次安装,但这次是从存储库而不是我下载的 tar。这似乎解决了问题。

sudo apt-get install python-imaging

虽然我还没有完全回答原来的问题,但我找到了替代解决方案,希望以上信息能够帮助遇到这种情况的其他人!

关于python - PIL 不会导入_imaging C 模块 : "*** The _imaging C module is not installed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4113095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com