2

I installed libjpeg and PIL, but when I try to save a JPG image, I always get this error:

ImportError: The _imaging C module is not installed

Any help much appreciated!

I tried to import _imaging w/ Python interpreter to see what's wrong and got this:

    >>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so
  Expected in: dynamic lookup
resopollution
  • 19,600
  • 10
  • 40
  • 49

4 Answers4

4

I just hit this as well on SL, and the problem is likely your libjpeg was built without a matching architecture. Assuming you're using MacPorts, run file /opt/local/lib/libjpeg.dylib. The right way is to build everything with MacPorts as +universal, see Universal Binaries in MacPorts as it relates to PIL dependencies.

Tim Hatch
  • 142
  • 6
4

A lot of these errors happen when compiling from source when you've previously installed python tools from fink or ports. For example the _jpeg_resync_to_restart error can happen when you've got leftover libjpeg files in /opt/local/lib. Try this:

cd /opt/local/lib
sudo rm *jpeg*

Then recompile libjpeg (starting with make clean), then recompile PIL (starting with rm -Rf build).

After that, import _imaging should work. Did for me anyway.

shacker
  • 14,712
  • 8
  • 89
  • 89
  • This worked for me, however, I also had conflicts from the fink package installer, which installs files in /sw. I also found the following answer to be helpful: http://stackoverflow.com/questions/8404956/installing-pil-with-jpeg-support-on-mac-os-x – Alexander Marquardt Jan 31 '13 at 14:34
2

Edit: Thanks for the added error message. This is apparently a problem with the jpeglib on Snow Leopard. Have you tried this?

http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • I followed this link to the dot and I still get this error :( - it seems whatever I try I can't get this to work, tried several sources on google already. – resopollution Oct 05 '09 at 07:13
  • I've also installed libjpeg7, libjpeg6 (I have not uninstalled any version - maybe this is why?). – resopollution Oct 05 '09 at 07:17
  • 1
    How did you install these libraries and to what location? Chances are that location is not in the dynamic load search path. Try running otool -L /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so – Ned Deily Oct 05 '09 at 07:39
  • @resopollution: OK, I don't have Snow Leopard, so I'm no more help now. :) – Lennart Regebro Oct 05 '09 at 08:50
  • 1
    Perhaps you have to reinstall PIL after having installed libjpeg. I'm running python and PIL on snow leopard without any problems. I installed libjpeg7 first for something else (libgd I think). – Markus Oct 05 '09 at 09:54
  • 2
    Oh, absolutely, you need to recompile it even, so you must remove the build directory under the PIL source and do a reinstall. The build process will not notice that the library has been updated, AFAIK. – Lennart Regebro Oct 05 '09 at 10:33
  • Tried everything , still no go :( – resopollution Oct 05 '09 at 18:26
  • same error everytime about "Symbol not found: _jpeg_resync_to_restart" seems other people have the problem, but no solution – resopollution Oct 05 '09 at 18:26
1

I kept having this problem as well. It turned out to be related to a change I made to my .bash_profile (forcing the usage of ggc-4.0) when trying to fix a MySQLdb installation problem.

http://www.brambraakman.com/blog/comments/installing_pil_in_snow_leopard_jpeg_resync_to_restart_error/