【问题标题】:PIL will not import the _imaging C module: "*** The _imaging C module is not installed"PIL 不会导入 _imaging C 模块:“*** The _imaging C module is not installed”
【发布时间】:2010-11-06 12:38:47
【问题描述】:

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.]

【问题讨论】:

    标签: python django ubuntu python-imaging-library imaging


    【解决方案1】:

    好像在我安装 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
    

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

    【讨论】:

      【解决方案2】:

      我通过安装开发 libjpeg 解决了这个问题:

      sudo apt-get install libjpeg8-dev
      

      然后完全重新安装 PIL 模块。

      (我使用的是虚拟环境,但它应该可以像标准运行 Python 一样工作)

      【讨论】:

        【解决方案3】:

        您尚未安装 libjpeg 库。这样做:

        sudo apt-get install libjpeg
        

        并重新运行 PIL 安装。

        【讨论】:

        • 这给了我错误:“E:找不到包 libjpeg”。我确实已经安装了 libjpeg62 - 这是等效的吗?
        • 不,我有 libjpeg62 和 libjpeg62-dev。
        • 我已经添加了更多关于它如何未能解决问题的详细信息
        • 我找到了解决此问题的替代方案,并将其添加到问题中。感谢您的建议!
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-05
        • 2021-03-07
        • 2019-12-03
        • 2020-12-01
        • 2012-03-22
        相关资源
        最近更新 更多