Category: Django

Installing PIL in Snow Leopard (_jpeg_resync_to_restart error)

In earlier posts I talked about my troubles with getting my Snow Leopard (Mac OS X 10.6) system fully equipped for work purposes:

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:

 

brambraakman$ python
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

File "", 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:

However, whatever way I tried installing libjpeg (download) and PIL, nothing was working. I also had a libjpeg version installed through Fink but the PIL installation never referenced that.

Running:

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.

Solution

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:

export CC="gcc-4.0"
export CXX="g++-4.0"

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.

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

  • Enjoyed this post? Please share it with others:
  • del.icio.us Favicon
  • Digg Favicon
  • Facebook Favicon
  • Google Favicon
  • LinkedIn Favicon
  • Reddit Favicon
  • Technorati Favicon
  • TwitThis Favicon
17 October 2009 • Apple, Django, Geek stuffComments (7)Permalink

Django Internationalization, gettext and Mac OS X

The Django Internationalization translation machinery uses the standard gettext module that comes with Python (supposedly). When I tried to update the message file for our translation with the following command:

python manage.py makemessages -l nl

I received the following error:

Error: errors happened while running xgettext on __init__.py
/bin/sh: xgettext: command not found

Uh oh...it seemed that my Mac OS X (Snow Leopard) was missing gettext, a set of tools that provides a framework to help other GNU packages produce multi-lingual messages. Even though I have Xcode installed on my system, I was still missing the gettext program.

How to solve this problem?

First, I did a Spotlight search for gettext and found that there was a gettext program in /sw/bin/ that seemed to be part of Fink (an open source software collection and package manager I played with for a little while when I tried fixing other installation problems). That gettext did not seem to be working correctly however, so I continued my search online.

There was not a lot of information to be found on this problem through Google but one hint was to install a program called Poedit and add a reference to it to the PATH variable (add this line to your .bash_profile or .profile - depending on which one you use - PATH=$PATH:/Applications/Poedit.app/Contents/MacOS/ ).

Now, however I got another error message when trying to update the message file:

Error: errors happened while running msguniq
/bin/sh: msguniq: command not found os x

I was unable to find any useful information on that error message online so I decided to try and start over again. Because I did not trust the Poedit.app solution to gettext completely, I decided to take a look at the /sw/bin/ version of gettext. That lead me to take another look into Fink - a distribution of Unix Open Source software for Mac OS X and Darwin and a package manager. It brings a wide range of free command-line and graphical software developed for Linux and similar operating systems to your Mac.

After having updated my Fink configuration (sudo fink configure) and repaired it (my Fink installation somehow got damaged), I searched through the package list (fink list) and installed gettext and gettext-tools (sudo fink install gettext-tools).

After adding the path to the gettext directory /sw/bin/ to my PATH variable (add PATH=$PATH:/sw/bin/ to your .bash_profile or .profile) and trying to update the message file again: it worked!

I am going to try out using Fink more often for installing certain open source software and libraries.

  • Enjoyed this post? Please share it with others:
  • del.icio.us Favicon
  • Digg Favicon
  • Facebook Favicon
  • Google Favicon
  • LinkedIn Favicon
  • Reddit Favicon
  • Technorati Favicon
  • TwitThis Favicon

Installing MySQLdb on Mac OS X Leopard

After many frustrating hours I finally managed to install MySQLdb for Python on my new Mac machine.

What went wrong? I made the mistake of installing a 64 bit version of MySQL 5.1 a couple of weeks ago. Python, however was build in 32 bit. There are many website dealing with this problem (see here and here) but it still did not seem to be solvable for me. After trying reinstalling the 32 bit MySQL and playing around with Fink (a package installer for Mac OS) I was about to try and start off from scratch. It turned out that even though I deleted the 64 bit MySQL and deleted the Fink MySQL package, some residual files where still left on the system. After removing all of the MySQL versions (both the Fink version in /sw/share/ and the MySQL package installed ones in /usr/local/mysql; /usr/local/mysql-version..) and reinstalling the right package one more time, I finally got MySQLdb too work. Here is moment of triumph:

Terminal Windows - MySQLdb install successful

The upside of my hours "wasted": I got to learn a little bit more about bash, building and compiling and setting colors on the terminal window.

  • Enjoyed this post? Please share it with others:
  • del.icio.us Favicon
  • Digg Favicon
  • Facebook Favicon
  • Google Favicon
  • LinkedIn Favicon
  • Reddit Favicon
  • Technorati Favicon
  • TwitThis Favicon
Page 1 of 1 pages