In earlier posts I talked about my troubles with getting my Snow Leopard (Mac OS X 10.6) system fully equipped for work purposes:
- Installing MySQLdb on Mac OS X Leopard
- Installing MySQL, Python, MySQLdb on Snow Leopard (Mac OS X 10.6) for Django
In the latest (and hopefully last) part of that saga, I tried to tackle a misbehaving Python Imaging Library (PIL) today. Earlier, I had already spent some hours trying to fix this problem but today I finally managed to overcome this problem. There are plenty of articles/blog posts already covering this problem and going over the installation steps. However, no matter how I followed these steps, it would not work.
I discovered the problem when trying to upload a picture through the Django Admin pages and received a standard Django error template stating that "The _imaging C module is not installed". Digging into this problem a little deeper I found that import the imaging library lists an error. Try this in your terminal:
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _imaging
This lead to an error that goes something like this:
>>> import _imaging
", line 1, in
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
Obviously there was something wrong with the jpeg support (libjpeg) in the imaging library. This _jpeg_resync_to_restart error has been encountered by many others as well:
- Snow Leopard Python 2.6 problems getting PIL to work
- libjpeg and Python Imaging (PIL) on Snow Leopard, check the comments to see how many people mentioned having this problem.
- Install PIL in Snow Leopard
otool -L /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so
will give you an overview of the dependencies of _imaging.so. It should return a reference to the libjpeg library.
I will not repeat the installation instructions for libjpeg and PIL again (you can find them in the links above). In the end I ended up using the new jpeg-7 library and using these instructions for installation.
What was wrong with my installation?
It turned out that the changes I made to install MySQLdb succesfully on my system had caused this problem. I had added:
to my .bash_profile which forces the system (at least that is how I understand it) to use an older version of the gcc compiler. Somehow this caused libjpeg (or PIL) to install incorrectly. Removing those lines from my .bash_profile and reinstalling libjpeg and PIL (for the nth time) finally resolved the problem.
I am relatively new to Mac OS X (and UNIX based programs and libraries) and might sometimes make mistakes that I am unaware of. The above fixed the problem for me and could very well be affecting your system as well. That does not mean that you should take my advice as expert advice or that what I think are related steps and solutions are always correct. You are welcome to correct (and educate) me by leaving a comment.