Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snow Leopard Python 2.6 problems getting PIL to work

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
like image 363
resopollution Avatar asked Dec 07 '25 08:12

resopollution


2 Answers

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.

like image 196
Tim Hatch Avatar answered Dec 09 '25 20:12

Tim Hatch


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.

like image 27
shacker Avatar answered Dec 09 '25 21:12

shacker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!