PIL不会导入

编程入门 行业动态 更新时间:2024-10-27 06:19:20
PIL不会导入_imaging C模块:“***未安装_imaging C模块”(PIL will not import the _imaging C module: “*** The _imaging C module is not installed”)

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

最满意答案

似乎在我安装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的版本不同。 这非常有意义。 这是我发现的另一个问题 。

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

sudo apt-get install python-imaging

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

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

*** The _imaging C module is not installed

I found a potential solution on another website suggesting that I force rebuild PIL from source:

sudo python setup.py build_ext -f

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:

_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

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

sudo apt-get install python-imaging

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!

更多推荐

本文发布于:2023-08-07 14:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464911.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PIL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!