开发者

PIL will not import the _imaging C module: "*** The _imaging C module is not installed"

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


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!


I fixed this by installing the development libjpeg:

sudo apt-get install libjpeg8-dev

Then re-install the PIL module altogether.

(I'm using a virtual environment, but it should work just as well running Python as standard)


You haven't installed the libjpeg library. Do this:

sudo apt-get install libjpeg

and re-run the PIL installation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜