Tuesday 15 November 2011

Installing Psycopg on Mac OS X (Lion) - Part 1

Introduction
As I had decided on PostgreSQL, Python and Django the first step was to get Django working and talking to the database (already correctly setup). On any sane platform this would have been a five minute job, not so for me.

Fink - Part 1
I need to install Psycopg2, go to the website and look at the instructions. This should be simple I can use Fink, oh no I can't I installed Fink before I upgraded and now it does work. OK, remove Fink and re-install and boot strap it (should be simple). Crap, for some reason I no longer have a C compiler. On to attempt two.

Mac Ports - Part 1
Nope, Mac Ports won't install it either as I need to upgrade. Ho hum... of course to install Mac Ports I now need to download XCode <tap fingers while it downloads>. Great, Mac Ports is being all whiny and won't work with some dependency problem; however, as I now have a C compiler I'll go back to Fink.

Fink - Part 2
After a long and tedious install session Fink claims to have installed Psycopg2. The Python interpreter disagrees with this as can't find the module.

ImportError: No module named psycopg
This is clearly some sort of path issue as Fink has placed it in

/sw/lib/python2.7/site-packages/psycopg2

As Mac OS X already has Python installed I decided that a symbolic link would probably be sufficient

cd /Library/Python/2.7/site-packages/
sudo ln -s  /sw/lib/python2.7/site-packages/psycopg2 psycopg2


I was wrong, while I could still not import psycopg any import of psycopg2 caused a segmentation fault (11).

Running the python2-7 executable in the /sw/bin directory (created by fink) showed that I could import the module without error. This would seem to indicate that the problem lies in how the package was built.


I'm not happy about replacing the standard Python that Apple installed with the fink version so I'm going to look at installing it myself.