Installing PsycoPG2 on OSX
June 7, 2009, 1:15 pm
Filed under: postgres

Today, I’ve been trying to get PsycoPG2 installed on my Macbook so that I can run through some tests and try and improve the user experience on Who’s Playing and hopefully increase it’s usage. I re-installed OSX the other week, and there’s still some little things like this to catch.

First off, I tried installing it via Macports, which worked Ok, but didn’t install it in a directory that the default Apple install of Python could see, it put it in the Macports directory. After a while I couldn’t find any way to change the install dir, so I ran:

python_switch python25

which lost all my other libraries, and the Django framework. Not quite what I wanted really.

python_switch python-apple

Will switch you back to the Apple install.

The easiest thing to do is just to download the latest psycopg2 tarball, and edit the setup.cfg file. I also installed Postgres from the official Mac binary, not from Macports, so I told it to use pg_config from that install. Uncomment the pg_config line and point it to your install of Postgres.


Then run

sudo python install

Job Done.

Update: For Snow Leopard users, you might also see the following error:

Symbol not found: _PQbackendPID

The solution, that I found on Kreegers blog, is to tell Snow Leopard that python needs to run in 32bit mode:

defaults write Prefer-32-Bit -bool yes


7 Comments so far
Leave a comment

Hi – so sorry for the delay in getting in contact. I was flagged up about your tweet regarding the UK Domino’s website. We did have a slight problem on Friday night – but can you give me some more details please? Can you drop me an email please?
Thanks. Georgina – Corporate Communications Manager.

Comment by Georgina Wald

[…] I then followed this to get psycopg2 installed to prep Postgresql for use with DJango […]

Pingback by Installing Postgresql for Mac for Django « Michael Bushe's Tech Blog

Holy crap, thank you so much for the Snow Leopard hint. I’ve been trying to solve that problem for days.

Comment by Jim

Thanks a lot for this. Setting up psycopg2 on Snow Leopard was turning out to be a huge pain until I found your article.

Comment by James

Thanks a lot. It worked perfectly.

Comment by exapted

very informative

Comment by Lashay Dewitz

When do I have to spec to run Python in 32-bit? Before or after the Python Install ???

Im running 8.4.5 on MacOS 10.6.6 and it still shows the Symbol not found: _PQbackendPID

Your help will be appreciated.

Comment by Vlad

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: